cache

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeFingerprint

func ComputeFingerprint(content string) string

ComputeFingerprint generates a SHA-256 hash of the content

Types

type CacheStats

type CacheStats struct {
	Entries    int
	MaxEntries int
	Hits       int64
	Misses     int64
	HitRate    float64
}

CacheStats holds cache statistics

type CacheStrategy

type CacheStrategy string
const (
	StrategyLRU  CacheStrategy = "lru"
	StrategyLFU  CacheStrategy = "lfu"
	StrategyFIFO CacheStrategy = "fifo"
)

type CachedResult

type CachedResult struct {
	Fingerprint    string
	OriginalSize   int
	Compressed     string
	CompressedSize int
	TokensSaved    int
	CreatedAt      time.Time
	ExpiresAt      time.Time
	AccessCount    int64 // accessed atomically
}

CachedResult holds a cached compression result

type FingerprintCache

type FingerprintCache struct {
	// contains filtered or unexported fields
}

FingerprintCache implements content-based caching using SHA-256 fingerprints. T35: Cache by content hash, not full content - enables: 1. Deduplication of identical outputs 2. Fast cache lookups for repeated content 3. Memory-efficient caching (hash keys vs full content)

func GetGlobalCache

func GetGlobalCache() *FingerprintCache

GetGlobalCache returns the global fingerprint cache

func NewFingerprintCache

func NewFingerprintCache(maxEntries int, ttl time.Duration) *FingerprintCache

NewFingerprintCache creates a new fingerprint-based cache

func (*FingerprintCache) Clear

func (fc *FingerprintCache) Clear()

Clear clears the cache

func (*FingerprintCache) Get

func (fc *FingerprintCache) Get(content string) *FingerprintResult

Get retrieves a cached result by content fingerprint

func (*FingerprintCache) GetByFingerprint

func (fc *FingerprintCache) GetByFingerprint(fp string) *FingerprintResult

GetByFingerprint retrieves a cached result by fingerprint

func (*FingerprintCache) Prune

func (fc *FingerprintCache) Prune() int

Prune removes expired entries

func (*FingerprintCache) Set

func (fc *FingerprintCache) Set(content string, compressed string, tokensSaved int)

Set stores a result in the cache

func (*FingerprintCache) SetByFingerprint

func (fc *FingerprintCache) SetByFingerprint(fp string, original string, compressed string, tokensSaved int)

SetByFingerprint stores a result with a known fingerprint

func (*FingerprintCache) Size

func (fc *FingerprintCache) Size() int

Size returns the number of entries in the cache

func (*FingerprintCache) Stats

func (fc *FingerprintCache) Stats() CacheStats

Stats returns cache statistics

type FingerprintResult

type FingerprintResult struct {
	Hash   string
	Hit    bool
	Cached *CachedResult
}

FingerprintResult holds the result of a fingerprint operation

type LRUCache

type LRUCache struct {
	// contains filtered or unexported fields
}

LRUCache provides a thread-safe LRU cache with TTL support. Uses interface{} for values to support different result types.

func NewLRUCache

func NewLRUCache(maxSize int, ttl time.Duration) *LRUCache

NewLRUCache creates an LRU cache with given max size and TTL.

func (*LRUCache) Get

func (c *LRUCache) Get(key string) interface{}

Get retrieves a cached value. Returns nil if not found or expired.

func (*LRUCache) Set

func (c *LRUCache) Set(key string, value interface{})

Set stores a value in the cache.

func (*LRUCache) Stats

func (c *LRUCache) Stats() LRUStats

Stats returns cache statistics.

type LRUStats

type LRUStats struct {
	Entries int
	MaxSize int
	Hits    int64
	Misses  int64
	HitRate float64
}

LRUStats holds basic LRU cache statistics.

type MultiLayerCache

type MultiLayerCache struct {
	// contains filtered or unexported fields
}

func NewMultiLayerCache

func NewMultiLayerCache(maxSize int) *MultiLayerCache

func (*MultiLayerCache) Delete

func (c *MultiLayerCache) Delete(key string)

func (*MultiLayerCache) GetString

func (c *MultiLayerCache) GetString(key string) (string, bool)

func (*MultiLayerCache) SetString

func (c *MultiLayerCache) SetString(key, value string)

func (*MultiLayerCache) Stats

func (c *MultiLayerCache) Stats() map[string]interface{}

type StringCacheItem

type StringCacheItem struct {
	// contains filtered or unexported fields
}

type StringFIFOCache

type StringFIFOCache struct {
	// contains filtered or unexported fields
}

func NewStringFIFOCache

func NewStringFIFOCache(capacity int) *StringFIFOCache

func (*StringFIFOCache) Delete

func (c *StringFIFOCache) Delete(key string)

func (*StringFIFOCache) Get

func (c *StringFIFOCache) Get(key string) (string, bool)

func (*StringFIFOCache) Len

func (c *StringFIFOCache) Len() int

func (*StringFIFOCache) Set

func (c *StringFIFOCache) Set(key, value string)

type StringLFUCache

type StringLFUCache struct {
	// contains filtered or unexported fields
}

func NewStringLFUCache

func NewStringLFUCache(capacity int) *StringLFUCache

func (*StringLFUCache) Delete

func (c *StringLFUCache) Delete(key string)

func (*StringLFUCache) Get

func (c *StringLFUCache) Get(key string) (string, bool)

func (*StringLFUCache) Len

func (c *StringLFUCache) Len() int

func (*StringLFUCache) Set

func (c *StringLFUCache) Set(key, value string)

Jump to

Keyboard shortcuts

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