cache

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotExist is returned if the entry does not exist.
	ErrNotExist = errors.New("entry does not exist")
)

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Get retrieves an entry. If the entry does not exist, ErrNotExist is
	// returned.
	Get(ctx context.Context, key string) ([]byte, error)
	// Set inserts an entry.
	Set(ctx context.Context, key string, data []byte, options *SetEntryOptions) error
	// Delete deletes an entry. If the entry does not exist, nothing is done and a
	// nil error is returned.
	Delete(ctx context.Context, key string) error
}

Cache stores key-value pairs for quick retrieval. It is safe to use a Cache implementation from multiple goroutines simultaneously.

type DiskCache

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

DiskCache implements Cache by storing values to disk.

func NewDiskCache

func NewDiskCache(path string) (*DiskCache, error)

NewDiskCache returns a DiskCache that stores its data in a file at the specified path.

func (*DiskCache) Close

func (d *DiskCache) Close() error

Close closes the cache.

func (*DiskCache) Collect

func (d *DiskCache) Collect(ch chan<- prometheus.Metric)

Collect implements prometheus.Collector.

func (*DiskCache) Delete

func (d *DiskCache) Delete(ctx context.Context, key string) error

Delete implements Cache.

func (*DiskCache) DeleteExpiredEntries

func (d *DiskCache) DeleteExpiredEntries(maxAge time.Time) (int, error)

DeleteExpiredEntries deletes all expired entries.

func (*DiskCache) Describe

func (d *DiskCache) Describe(descs chan<- *prometheus.Desc)

Describe implements prometheus.Collector.

func (*DiskCache) Get

func (d *DiskCache) Get(ctx context.Context, key string) ([]byte, error)

Get implements Cache.

func (*DiskCache) Set

func (d *DiskCache) Set(ctx context.Context, key string, data []byte, options *SetEntryOptions) error

Set implements Cache.

type SetEntryOptions

type SetEntryOptions struct {
	// Expires optionally controls when an entry should be invalidated.
	Expires time.Time
}

Jump to

Keyboard shortcuts

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