Sphire Mantis' API Documentation
import "github.com/sphireinc/mantis/cache"
RELEASED is a status enum for a released item UPDATED is a status enum for an updated value in an existing kv item CREATED is a status enum for a created kv item NOOP is a status for no operation
const (
RELEASED = iota
UPDATED
CREATED
NOOP
)
func filename(key string) string
func hash(key string) string
func newTmpDir() string
BigCache primary struct with bigcache pointer and config
type BigCache struct {
Cache *bigcache.BigCache
Config bigcache.Config
}
func (b *BigCache) Init() error
Init creates a new Allegro BigCache based on b.Config
DiskCache primary struct with an array of diskCache (key:filename) and the primary directory
type DiskCache struct {
data []diskCache
directory string
}
func New() *DiskCache
New creates a new DiskCache using the tmp directory
func (D *DiskCache) Get(key string) (any, error)
Get the data pointed to by a key
func (D *DiskCache) Set(key string, data any) error
Set some data to a given key
func (D *DiskCache) newTmpFile(key string) *os.File
MemCache primary struct for victorspringers http-cache
type MemCache struct {
Client *cache.Client
Algorithm memory.Algorithm
Capacity int
RefreshKey string
memCacheTime time.Duration
}
func NewMemCache(algorithm memory.Algorithm, capacity int, refreshKey string, cacheTime time.Duration) MemCache
NewMemCache creates a new MemCache instance
func (m *MemCache) Init() error
Init starts our in-memory cache.
func (m *MemCache) String() string
Memory holds our cache
type Memory struct {
mutex sync.RWMutex
capacity int64
store map[uint64]item
Config memoryConfig
}
func NewMemoryCache(capacity int64, expiry string) *Memory
NewMemoryCache creates and returns a new in memory cache
func (m *Memory) Get(key uint64) (any, bool)
Get the value associated with a key in our cache
func (m *Memory) Release(key uint64)
Release an item from our memory cache
func (m *Memory) Set(key uint64, value any, expiration time.Time)
Set a new kv pair in our memory cache
func (m *Memory) checkExpireAndUpdate(key uint64, toStore item) int
checkExpireAndUpdate checks if KV has expired, if not updates toStore item returns false if released, true if updated
func (m *Memory) evict()
evict records from memory on an LRU basis
func (m *Memory) triggerEvict()
triggerEvict checks if we need to evict data, and commences eviction if so
type diskCache struct {
key string
filename string
}
item is an item and its metadata in our cache
type item struct {
value any
lastAccessed time.Time
expiration time.Time
}
memoryConfig holds our expiry configuration
type memoryConfig struct {
Expiry time.Duration
DefaultExpiry time.Duration
}
Generated by gomarkdoc