cache

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 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.

func OpenStores added in v0.1.0

func OpenStores(db *bolt.DB) (*ProviderCache, *MonikerCache, error)

OpenStores atomically initializes every bucket used by the standalone monitor and returns cache handles backed by the supplied 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