cache

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrHostnameRequired is returned if the given hostName to New is not given.
	ErrHostnameRequired = errors.New("hostName is required")

	// ErrHostnameMustNotContainScheme is returned if the given hostName to New contained a scheme.
	ErrHostnameMustNotContainScheme = errors.New("hostName must not contain scheme")

	// ErrHostnameNotValid is returned if the given hostName to New is not valid.
	ErrHostnameNotValid = errors.New("hostName is not valid")

	// ErrHostnameMustNotContainPath is returned if the given hostName to New contained a path.
	ErrHostnameMustNotContainPath = errors.New("hostName must not contain a path")

	// ErrAlreadyExists is returned when attempting to store a narinfo/nar that already exists in the database.
	ErrAlreadyExists = errors.New("narinfo or nar already exists")

	// ErrInconsistentState is returned when the database is in an inconsistent state (e.g., nar exists without narinfo).
	ErrInconsistentState = errors.New("inconsistent database state")
)

Functions

This section is empty.

Types

type Cache

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

Cache represents the main cache service.

func New

func New(
	ctx context.Context,
	hostName string,
	db database.Querier,

	configStore storage.ConfigStore,
	narInfoStore storage.NarInfoStore,
	narStore storage.NarStore,
	secretKeyPath string,
	downloadLocker lock.Locker,
	cacheLocker lock.RWLocker,
	downloadLockTTL time.Duration,
	cacheLockTTL time.Duration,
) (*Cache, error)

New returns a new Cache.

func (*Cache) AddLRUCronJob added in v0.0.11

func (c *Cache) AddLRUCronJob(ctx context.Context, schedule cron.Schedule)

AddLRUCronJob adds a job for LRU.

func (*Cache) AddUpstreamCaches added in v0.0.11

func (c *Cache) AddUpstreamCaches(ctx context.Context, ucs ...*upstream.Cache)

AddUpstreamCaches adds one or more upstream caches with lazy loading support.

func (*Cache) DeleteNar added in v0.0.4

func (c *Cache) DeleteNar(ctx context.Context, narURL nar.URL) error

DeleteNar deletes the nar from the store.

func (*Cache) DeleteNarInfo added in v0.0.4

func (c *Cache) DeleteNarInfo(ctx context.Context, hash string) error

DeleteNarInfo deletes the narInfo from the store.

func (*Cache) GetHealthChecker added in v0.3.0

func (c *Cache) GetHealthChecker() *healthcheck.HealthChecker

GetHealthChecker returns the instance of haelth checker used by the cache. It's useful for testing the behavior of ncps.

func (*Cache) GetHealthyUpstreamCount added in v0.6.0

func (c *Cache) GetHealthyUpstreamCount() int

GetHealthyUpstreamCount returns the number of healthy upstream caches.

func (*Cache) GetHostname

func (c *Cache) GetHostname() string

GetHostname returns the hostname.

func (*Cache) GetNar

func (c *Cache) GetNar(ctx context.Context, narURL nar.URL) (int64, io.ReadCloser, error)

GetNar returns the nar given a hash and compression from the store. If the nar is not found in the store, it's pulled from an upstream, stored in the stored and finally returned. NOTE: It's the caller responsibility to close the body.

func (*Cache) GetNarInfo

func (c *Cache) GetNarInfo(ctx context.Context, hash string) (*narinfo.NarInfo, error)

GetNarInfo returns the narInfo given a hash from the store. If the narInfo is not found in the store, it's pulled from an upstream, stored in the stored and finally returned.

func (*Cache) PublicKey

func (c *Cache) PublicKey() signature.PublicKey

PublicKey returns the public key of the server.

func (*Cache) PutNar added in v0.0.3

func (c *Cache) PutNar(ctx context.Context, narURL nar.URL, r io.ReadCloser) error

PutNar records the NAR (given as an io.Reader) into the store.

func (*Cache) PutNarInfo added in v0.0.3

func (c *Cache) PutNarInfo(ctx context.Context, hash string, r io.ReadCloser) error

PutNarInfo records the narInfo (given as an io.Reader) into the store and signs it.

func (*Cache) RegisterUpstreamMetrics added in v0.6.0

func (c *Cache) RegisterUpstreamMetrics(m metric.Meter) error

RegisterUpstreamMetrics register metrics related to upstream caches.

func (*Cache) SetCacheSignNarinfo added in v0.2.0

func (c *Cache) SetCacheSignNarinfo(shouldSignNarinfo bool)

SetCacheSignNarinfo configure ncps to sign or not sign narinfos.

func (*Cache) SetMaxSize added in v0.0.11

func (c *Cache) SetMaxSize(maxSize uint64)

SetMaxSize sets the maxsize of the cache. This will be used by the LRU cronjob to automatically clean-up the store.

func (*Cache) SetRecordAgeIgnoreTouch added in v0.0.6

func (c *Cache) SetRecordAgeIgnoreTouch(d time.Duration)

SetRecordAgeIgnoreTouch changes the duration at which a record is considered up to date and a touch is not invoked.

func (*Cache) SetTempDir added in v0.3.0

func (c *Cache) SetTempDir(d string)

SetTempDir sets the temporary directory.

func (*Cache) SetupCron added in v0.0.11

func (c *Cache) SetupCron(ctx context.Context, timezone *time.Location)

SetupCron creates a cron instance in the cache.

func (*Cache) StartCron added in v0.0.11

func (c *Cache) StartCron(ctx context.Context)

StartCron starts the cron scheduler in its own go-routine, or no-op if already started.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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