MCPcopy Create free account
hub / github.com/PacktPublishing/System-Programming-Essentials-with-Go / Cache

Struct Cache

ch13/cache.go:22–27  ·  view source on GitHub ↗

Cache represents a thread-safe in-memory cache with TTL and LRU eviction policies

Source from the content-addressed store, hash-verified

20
21// Cache represents a thread-safe in-memory cache with TTL and LRU eviction policies
22type Cache struct {
23 mu sync.RWMutex
24 items map[string]*list.Element // Map of keys to list elements
25 eviction *list.List // Doubly-linked list for eviction
26 capacity int // Maximum number of items in the cache
27}
28
29// NewCache initializes and returns a new Cache with the given capacity
30func NewCache(capacity int) *Cache {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected