Documentation
¶
Overview ¶
Package lrucache provides a very basic LRU cache implementation.
The lru package provides a very basic LRU cache implementation
Index ¶
- type Cache
- type LRUCache
- func (c *LRUCache) Add(key, value interface{}) (evicted bool)
- func (c *LRUCache) Contains(key interface{}) (ok bool)
- func (c *LRUCache) Export(w io.Writer) error
- func (c *LRUCache) ExportToFile(path string) error
- func (c *LRUCache) ExportToFileAtomic(path string) error
- func (c *LRUCache) Get(key interface{}) (value interface{}, ok bool)
- func (c *LRUCache) Import(r io.Reader) error
- func (c *LRUCache) ImportFromFile(path string) error
- func (c *LRUCache) Keys() []interface{}
- func (c *LRUCache) Length() int
- func (c *LRUCache) Purge()
- func (c *LRUCache) Remove(key interface{}) bool
- func (c *LRUCache) Snapshot() (size int, entries []Pair)
- type Pair
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface {
// Add a new value to the cache and updates the recent-ness.
// Returns true if an eviction occurred.
Add(key, value interface{}) bool
// Return a key's value if found in the cache and updates the recent-ness.
Get(key interface{}) (value interface{}, ok bool)
// Check if a key exists without updating the recent-ness.
Contains(key interface{}) (ok bool)
// Remove a key from the cache.
Remove(key interface{}) bool
// Return a slice with all keys ordered MRU -> LRU.
Keys() []interface{}
// Return number of entries in the cache.
Length() int
// Remove all entries from the cache.
Purge()
}
Cache defines the interface for the LRU cache
type LRUCache ¶
type LRUCache struct {
// contains filtered or unexported fields
}
LRU struct to represent the LRU cache
func NewLRUCache ¶
New constructs a new cache instance
func (*LRUCache) Export ¶ added in v0.3.6
Export writes size + entries (MRU -> LRU) in gob format WITHOUT holding locks during encoding.
func (*LRUCache) ExportToFile ¶ added in v0.3.6
ExportToFile writes (non-atomic) to a file path.
func (*LRUCache) ExportToFileAtomic ¶ added in v0.3.6
ExportToFileAtomic writes to a temp file and atomically renames it.
func (*LRUCache) Import ¶ added in v0.3.6
Import replaces the cache contents, preserving LRU order. Assumes Entries are MRU -> LRU (same as Export).
func (*LRUCache) ImportFromFile ¶ added in v0.3.6
Click to show internal directories.
Click to hide internal directories.