cache

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Get(ctx context.Context, key string) ([]byte, error)
	Set(ctx context.Context, key string, data []byte, ttl time.Duration) error
	Delete(ctx context.Context, key string) error
	Clear(ctx context.Context) error
	Size(ctx context.Context) (int64, error)
	Cleanup(ctx context.Context) error
	GetStats(ctx context.Context) (*Stats, error)
}

Cache defines the interface for local file caching operations

type Entry

type Entry struct {
	Key       string    `json:"key"`
	Data      []byte    `json:"data"`
	CreatedAt time.Time `json:"created_at"`
	ExpiresAt time.Time `json:"expires_at"`
	Size      int64     `json:"size"`
}

Entry represents a cache entry with metadata

type FileCache

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

FileCache implements the Cache interface using the filesystem

func NewFileCache

func NewFileCache(
	directory string,
	maxSizeMB int,
	defaultTTL time.Duration,
) (*FileCache, error)

NewFileCache creates a new file-based cache

func (*FileCache) Cleanup

func (c *FileCache) Cleanup(ctx context.Context) error

Cleanup removes expired entries

func (*FileCache) Clear

func (c *FileCache) Clear(ctx context.Context) error

Clear removes all entries from cache

func (*FileCache) Close

func (c *FileCache) Close() error

Close is a no-op retained for interface compatibility

func (*FileCache) Delete

func (c *FileCache) Delete(ctx context.Context, key string) error

Delete removes an entry from cache

func (*FileCache) Get

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

Get retrieves data from cache

func (*FileCache) GetStats

func (c *FileCache) GetStats(ctx context.Context) (*Stats, error)

GetStats returns cache statistics

func (*FileCache) Set

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

Set stores data in cache with TTL

func (*FileCache) Size

func (c *FileCache) Size(ctx context.Context) (int64, error)

Size returns the total size of cached data

type Stats

type Stats struct {
	TotalEntries int64   `json:"total_entries"`
	TotalSize    int64   `json:"total_size"`
	HitRate      float64 `json:"hit_rate"`
	MissRate     float64 `json:"miss_rate"`
	Hits         int64   `json:"hits"`
	Misses       int64   `json:"misses"`
}

Stats represents cache statistics for external consumption

Jump to

Keyboard shortcuts

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