cache

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 5 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 retrieves a value from the cache
	Get(ctx context.Context, key string) ([]byte, bool)

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

	// Delete removes a value from the cache
	Delete(ctx context.Context, key string) error

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

	// Stats returns cache statistics
	Stats() CacheStats
}

Cache is the interface for response caching

func NewLRUCache

func NewLRUCache(config *Config) Cache

NewLRUCache creates a new LRU cache

type CacheStats

type CacheStats struct {
	Hits   uint64
	Misses uint64
	Size   uint64
	Items  uint64
}

CacheStats represents cache statistics

type Config

type Config struct {
	// MaxSize is the maximum cache size in bytes (default: 100MB)
	MaxSize int64

	// MaxItems is the maximum number of items (default: 10000)
	MaxItems int

	// DefaultTTL is the default TTL for cached items (default: 5 minutes)
	DefaultTTL time.Duration

	// Enabled indicates whether caching is enabled
	Enabled bool
}

Config holds cache configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a default cache configuration

Jump to

Keyboard shortcuts

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