Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidMaxCost indicates MaxCost is not positive. ErrInvalidMaxCost = errors.New("MaxCost must be positive") // ErrInvalidNumCounters indicates NumCounters is not positive. ErrInvalidNumCounters = errors.New("NumCounters must be positive") // ErrInvalidBufferItems indicates BufferItems is not positive. ErrInvalidBufferItems = errors.New("BufferItems must be positive") )
Sentinel errors for cache validation.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache provides a high-performance in-memory cache
func (*Cache) Get ¶
Get retrieves a value from the cache and checks TTL expiration.
This method performs both ristretto cache lookup and TTL validation. If the value has expired based on its TTL, it's automatically deleted and treated as a cache miss. The TTL check is performed atomically to prevent race conditions.
Returns the cached value and true if found and not expired, or nil and false if not found or expired.
func (*Cache) Set ¶
Set stores a value in the cache with TTL (time-to-live).
The value is stored with an estimated cost (64 bytes base overhead). If the cache is full and cannot evict items, the set operation may fail silently. This is by design in Ristretto to maintain performance.
TTL is tracked separately and enforced on Get() and by a background cleanup goroutine that runs every 30 seconds. Setting ttl to 0 means the value never expires (until explicitly deleted or evicted).
This method is thread-safe and can be called concurrently.
type Config ¶
type Config struct {
// MaxCost is the maximum cost of cache entries (in bytes approximately)
MaxCost int64
// NumCounters is the number of keys to track frequency
NumCounters int64
// BufferItems is the size of the internal buffer
BufferItems int64
}
Config holds cache configuration
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns sensible defaults for the cache
type ValidationError ¶ added in v1.0.0
ValidationError wraps cache configuration validation errors with context.
func (*ValidationError) Error ¶ added in v1.0.0
func (e *ValidationError) Error() string
func (*ValidationError) Unwrap ¶ added in v1.0.0
func (e *ValidationError) Unwrap() error