cache

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Refresh intervals based on provider state
	OnlineCheckInterval     = 1 * time.Minute
	RecentOfflineInterval   = 5 * time.Minute
	LongTermOfflineInterval = 6 * time.Hour

	// Threshold for long-term offline
	LongTermOfflineThreshold = 5
)

Variables

This section is empty.

Functions

func MigrateFromJSON

func MigrateFromJSON(db *bolt.DB, jsonData []byte) error

MigrateFromJSON imports aktop-format JSON provider cache into bbolt. This is a one-time migration helper. Pass nil to skip.

func OpenDB

func OpenDB(path string) (*bolt.DB, error)

OpenDB opens or creates a bbolt database at the given path. Callers are responsible for closing the returned database.

Types

type CachedProvider

type CachedProvider struct {
	HostURI             string            `json:"host_uri"`
	Name                string            `json:"name"`
	Country             string            `json:"country"`
	Attributes          map[string]string `json:"attributes"`
	IsOnline            bool              `json:"is_online"`
	Version             string            `json:"version"`
	CPUAvailable        uint64            `json:"cpu_available"`
	CPUTotal            uint64            `json:"cpu_total"`
	MemAvailable        uint64            `json:"mem_available"`
	MemTotal            uint64            `json:"mem_total"`
	GPUAvailable        uint64            `json:"gpu_available"`
	GPUTotal            uint64            `json:"gpu_total"`
	GPUModels           []string          `json:"gpu_models,omitempty"`
	LastSeenOnline      time.Time         `json:"last_seen_online"`
	LastChecked         time.Time         `json:"last_checked"`
	ConsecutiveFailures int               `json:"consecutive_failures"`
}

CachedProvider represents a provider with cached status information.

type MonikerCache

type MonikerCache struct {
	// contains filtered or unexported fields
}

MonikerCache stores validator pubkey -> moniker mappings in bbolt.

func OpenMonikerCache

func OpenMonikerCache(db *bolt.DB) (*MonikerCache, error)

OpenMonikerCache opens or creates the moniker cache in the given bbolt database.

func (*MonikerCache) Get

func (c *MonikerCache) Get() map[string]string

Get returns all monikers as a map.

func (*MonikerCache) HasMonikers

func (c *MonikerCache) HasMonikers() bool

HasMonikers returns true if the cache has any entries.

func (*MonikerCache) Save

func (c *MonikerCache) Save() error

Save is a no-op for bbolt — data is already persisted on each write.

func (*MonikerCache) Set

func (c *MonikerCache) Set(monikers map[string]string)

Set replaces all monikers with the given map.

type ProviderCache

type ProviderCache struct {
	// contains filtered or unexported fields
}

ProviderCache manages provider data inside a bbolt database.

func Open

func Open(db *bolt.DB) (*ProviderCache, error)

Open opens or creates the provider cache in the given bbolt database. It ensures the required buckets exist.

func (*ProviderCache) GetAllProviders

func (c *ProviderCache) GetAllProviders() map[string]*CachedProvider

GetAllProviders returns all cached providers.

func (*ProviderCache) GetOnlineProviders

func (c *ProviderCache) GetOnlineProviders() []*CachedProvider

GetOnlineProviders returns all providers that are currently online.

func (*ProviderCache) GetProvider

func (c *ProviderCache) GetProvider(owner string) (*CachedProvider, bool)

GetProvider returns a provider by owner address.

func (*ProviderCache) GetProvidersByPriority

func (c *ProviderCache) GetProvidersByPriority() []string

GetProvidersByPriority returns providers sorted by check priority: unchecked (0) > online (1) > recently offline (2) > long-term offline (3)

func (*ProviderCache) GetProvidersDueForCheck

func (c *ProviderCache) GetProvidersDueForCheck() []string

GetProvidersDueForCheck returns providers that need to be checked based on smart scheduling.

func (*ProviderCache) HasProviders

func (c *ProviderCache) HasProviders() bool

HasProviders returns true if the cache has any providers.

func (*ProviderCache) MarkProviderOffline

func (c *ProviderCache) MarkProviderOffline(owner string)

MarkProviderOffline marks a provider as offline.

func (*ProviderCache) MarkProviderOnline

func (c *ProviderCache) MarkProviderOnline(owner, version string, cpuAvail, cpuTotal, memAvail, memTotal, gpuAvail, gpuTotal uint64, gpuModels []string)

MarkProviderOnline marks a provider as online with updated stats.

func (*ProviderCache) OnlineCount

func (c *ProviderCache) OnlineCount() int

OnlineCount returns the number of online providers.

func (*ProviderCache) ProviderCount

func (c *ProviderCache) ProviderCount() int

ProviderCount returns the total number of providers in cache.

func (*ProviderCache) Save

func (c *ProviderCache) Save() error

Save is a no-op for bbolt — data is already persisted on each write.

func (*ProviderCache) SyncWithChain

func (c *ProviderCache) SyncWithChain(onChainProviders []rpc.OnChainProvider) []string

SyncWithChain syncs the cache with on-chain providers. Returns a list of new provider owners that weren't in the cache.

type ProviderStore

type ProviderStore interface {
	HasProviders() bool
	GetProvider(owner string) (*CachedProvider, bool)
	GetAllProviders() map[string]*CachedProvider
	GetOnlineProviders() []*CachedProvider
	MarkProviderOnline(owner, version string, cpuAvail, cpuTotal, memAvail, memTotal, gpuAvail, gpuTotal uint64, gpuModels []string)
	MarkProviderOffline(owner string)
	SyncWithChain(onChainProviders []rpc.OnChainProvider) []string
	GetProvidersDueForCheck() []string
	GetProvidersByPriority() []string
	ProviderCount() int
	OnlineCount() int
	Save() error
}

ProviderStore defines the interface for provider caching operations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL