Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitGlobalCache ¶
InitGlobalCache initializes the global cache with the given directory.
Types ¶
type BadgerCache ¶
type BadgerCache struct {
// contains filtered or unexported fields
}
BadgerCache implements the Cache interface using Badger DB.
func GetBadgerCache ¶
func GetBadgerCache() (*BadgerCache, bool)
GetBadgerCache returns the global cache as a BadgerCache if applicable.
func NewBadgerCache ¶
func NewBadgerCache(dir string) (*BadgerCache, error)
NewBadgerCache creates a new Badger-based cache.
func (*BadgerCache) Clear ¶
func (c *BadgerCache) Clear() error
Clear removes all items from the cache.
func (*BadgerCache) Close ¶
func (c *BadgerCache) Close() error
Close closes the badger database and stops the background GC goroutine.
func (*BadgerCache) Delete ¶
func (c *BadgerCache) Delete(key string) error
Delete removes an item from the cache.
type Cache ¶
type Cache interface {
// Get retrieves data from the cache, returning whether it was found
Get(key string, dest interface{}) (bool, error)
// Set stores data in the cache with optional TTL
Set(key string, data interface{}, ttl time.Duration) error
// Delete removes an item from the cache
Delete(key string) error
// Clear removes all items from the cache
Clear() error
// Close closes the cache and releases any resources
Close() error
}
Cache defines the interface for the caching system.
func GetNamespacedCache ¶ added in v1.0.7
GetNamespacedCache returns (and initializes if needed) a cache scoped to the provided namespace. Namespaced caches live alongside the global cache but operate on their own storage so they aren't affected by global cache invalidation.
type CacheItem ¶
type CacheItem struct {
Data json.RawMessage `json:"data"` // Store as raw JSON to avoid double marshaling
Timestamp int64 `json:"timestamp"`
TTL int64 `json:"ttl"` // TTL in seconds, 0 means no expiration
}
CacheItem represents an item in the cache with TTL.
type FileCache ¶
type FileCache struct {
// contains filtered or unexported fields
}
FileCache implements a simple file-based cache with LRU eviction.
func NewFileCache ¶
NewFileCache creates a new file-based cache with optional size limit. maxSize of 0 means unlimited cache size.
func NewFileCacheWithSize ¶ added in v1.0.7
NewFileCacheWithSize creates a new file-based cache with a maximum size limit. When the cache exceeds maxSize items, least recently used items are evicted. maxSize of 0 means unlimited cache size.
func NewMemoryCache ¶
func NewMemoryCache() *FileCache
NewMemoryCache creates an in-memory only cache (no persistence).
func NewMemoryCacheWithSize ¶ added in v1.0.7
NewMemoryCacheWithSize creates an in-memory cache with a size limit.
func (*FileCache) Close ¶
Close implements the Cache.Close method for FileCache This is a no-op for FileCache since it doesn't maintain any resources that need explicit closing.