Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface { // Get retrieves items from the cache by key. // If an item for a particular key is not found, its position in the result will be nil. Get(keys ...string) []Item // Put adds an item to the cache. Put(key string, item Item) // Remove clears items with the given keys from the cache Remove(keys ...string) // Size returns the size of all items currently in the cache. Size() uint64 }
Cache is a bounded-size in-memory cache of sized items with a configurable eviction policy
func New ¶
func New(capacity uint64, options ...CacheOption) Cache
New returns a cache with the requested options configured. The cache consumes memory bounded by a fixed capacity, plus tracking overhead linear in the number of items.
type CacheOption ¶
type CacheOption func(*cache)
CacheOption configures a cache.
func EvictionPolicy ¶
func EvictionPolicy(policy Policy) CacheOption
EvictionPolicy sets the eviction policy to be used to make room for new items. If not provided, default is LeastRecentlyUsed.
type Item ¶
type Item interface { // Size returns the item's size, in bytes Size() uint64 }
Item is an item in a cache
Click to show internal directories.
Click to hide internal directories.