Documentation
¶
Overview ¶
Package cache provides a simple in-memory cache with TTL support.
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. Returns nil if not found or expired.
Get(key string) (any, bool)
// Set stores a value in the cache with the specified TTL.
Set(key string, value any, ttl time.Duration)
// Delete removes a value from the cache.
Delete(key string)
// Clear removes all values from the cache.
Clear()
// Stats returns cache statistics.
Stats() CacheStats
}
Cache provides thread-safe caching with expiration support.
func NewMemoryCache ¶
NewMemoryCache creates a new in-memory cache with automatic cleanup. The cleanupInterval determines how often expired entries are removed.
func NewNoOpCache ¶
func NewNoOpCache() Cache
NewNoOpCache creates a cache that doesn't cache anything.
type CacheStats ¶
type CacheStats struct {
Hits int64 // Number of successful Get operations
Misses int64 // Number of failed Get operations (not found or expired)
Sets int64 // Number of Set operations
Evictions int64 // Number of expired entries cleaned up
CurrentSize int // Current number of cached entries
}
CacheStats holds cache performance metrics.
Click to show internal directories.
Click to hide internal directories.