Help us shape the future of Go! Take the 2026 Go Developer Survey

cache

package
v1.233.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCacheMiss indicates the requested key was not found in cache.
	ErrCacheMiss = errors.New("cache miss")

	// ErrCacheExpired indicates the cached entry has expired.
	ErrCacheExpired = errors.New("cache expired")
)

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Data      []byte    `json:"data"`
	CachedAt  time.Time `json:"cached_at"`
	ExpiresAt time.Time `json:"expires_at"`
}

Entry represents a cached entry with metadata.

type FileStore

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

FileStore implements file-based caching.

func NewFileStore

func NewFileStore(baseDir string) *FileStore

NewFileStore creates a new file-based cache store.

func (*FileStore) Clear

func (fs *FileStore) Clear(ctx context.Context) error

Clear removes all entries from the cache.

func (*FileStore) Delete

func (fs *FileStore) Delete(ctx context.Context, key string) error

Delete removes an entry from the cache.

func (*FileStore) Get

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

Get retrieves data from the file cache.

func (*FileStore) IsExpired

func (fs *FileStore) IsExpired(ctx context.Context, key string) (bool, error)

IsExpired checks if a cache entry is expired.

func (*FileStore) Set

func (fs *FileStore) Set(ctx context.Context, key string, data []byte, ttl time.Duration) error

Set stores data in the file cache.

type Store

type Store interface {
	// Get retrieves data from cache. Returns ErrCacheMiss if not found or expired.
	Get(ctx context.Context, key string) ([]byte, error)

	// Set stores data in cache with the specified TTL.
	Set(ctx context.Context, key string, data []byte, ttl time.Duration) error

	// Delete removes an entry from cache.
	Delete(ctx context.Context, key string) error

	// Clear removes all entries from cache.
	Clear(ctx context.Context) error

	// IsExpired checks if a cache entry is expired without reading it.
	IsExpired(ctx context.Context, key string) (bool, error)
}

Store defines the interface for cache operations.

Jump to

Keyboard shortcuts

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