Sphire Mantis API Documentation

Sphire Mantis' API Documentation

View the Project on GitHub sphireinc/Mantis

Go Report Card Go Reference

cache

import "github.com/sphireinc/mantis/cache"

Index

Constants

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

func filename(key string) string

func hash

func hash(key string) string

func newTmpDir

func newTmpDir() string

type BigCache

BigCache primary struct with bigcache pointer and config

type BigCache struct {
    Cache  *bigcache.BigCache
    Config bigcache.Config
}

func (*BigCache) Init

func (b *BigCache) Init() error

Init creates a new Allegro BigCache based on b.Config

type DiskCache

DiskCache primary struct with an array of diskCache (key:filename) and the primary directory

type DiskCache struct {
    data      []diskCache
    directory string
}

func New

func New() *DiskCache

New creates a new DiskCache using the tmp directory

func (*DiskCache) Get

func (D *DiskCache) Get(key string) (any, error)

Get the data pointed to by a key

func (*DiskCache) Set

func (D *DiskCache) Set(key string, data any) error

Set some data to a given key

func (*DiskCache) newTmpFile

func (D *DiskCache) newTmpFile(key string) *os.File

type MemCache

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

func NewMemCache(algorithm memory.Algorithm, capacity int, refreshKey string, cacheTime time.Duration) MemCache

NewMemCache creates a new MemCache instance

func (*MemCache) Init

func (m *MemCache) Init() error

Init starts our in-memory cache.

func (*MemCache) String

func (m *MemCache) String() string

type Memory

Memory holds our cache

type Memory struct {
    mutex    sync.RWMutex
    capacity int64
    store    map[uint64]item
    Config   memoryConfig
}

func NewMemoryCache

func NewMemoryCache(capacity int64, expiry string) *Memory

NewMemoryCache creates and returns a new in memory cache

func (*Memory) Get

func (m *Memory) Get(key uint64) (any, bool)

Get the value associated with a key in our cache

func (*Memory) Release

func (m *Memory) Release(key uint64)

Release an item from our memory cache

func (*Memory) Set

func (m *Memory) Set(key uint64, value any, expiration time.Time)

Set a new kv pair in our memory cache

func (*Memory) checkExpireAndUpdate

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 (*Memory) evict

func (m *Memory) evict()

evict records from memory on an LRU basis

func (*Memory) triggerEvict

func (m *Memory) triggerEvict()

triggerEvict checks if we need to evict data, and commences eviction if so

type diskCache

type diskCache struct {
    key      string
    filename string
}

type item

item is an item and its metadata in our cache

type item struct {
    value        any
    lastAccessed time.Time
    expiration   time.Time
}

type memoryConfig

memoryConfig holds our expiry configuration

type memoryConfig struct {
    Expiry        time.Duration
    DefaultExpiry time.Duration
}

Generated by gomarkdoc