cache

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitGlobalCache

func InitGlobalCache(cacheDir string) error

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

func (*BadgerCache) Delete

func (c *BadgerCache) Delete(key string) error

Delete removes an item from the cache

func (*BadgerCache) Get

func (c *BadgerCache) Get(key string, dest interface{}) (bool, error)

Get retrieves data from the cache

func (*BadgerCache) Set

func (c *BadgerCache) Set(key string, data interface{}, ttl time.Duration) error

Set stores data in 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 GetGlobalCache

func GetGlobalCache() Cache

GetGlobalCache returns the global cache instance

type CacheItem

type CacheItem struct {
	Data      interface{} `json:"data"`
	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

func NewFileCache

func NewFileCache(cacheDir string, persisted bool) (*FileCache, error)

NewFileCache creates a new file-based cache

func NewMemoryCache

func NewMemoryCache() *FileCache

NewMemoryCache creates an in-memory only cache (no persistence)

func (*FileCache) Clear

func (c *FileCache) Clear() error

Clear removes all items from the cache

func (*FileCache) Close

func (c *FileCache) Close() error

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

func (*FileCache) Delete

func (c *FileCache) Delete(key string) error

Delete removes an item from the cache

func (*FileCache) Get

func (c *FileCache) Get(key string, dest interface{}) (bool, error)

Get retrieves data from the cache

func (*FileCache) Set

func (c *FileCache) Set(key string, data interface{}, ttl time.Duration) error

Set stores data in the cache

Jump to

Keyboard shortcuts

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