go-vitess.v1: gopkg.in/src-d/go-vitess.v1/cache Index | Files

package cache

import "gopkg.in/src-d/go-vitess.v1/cache"

Package cache implements a LRU cache.

The implementation borrows heavily from SmallLRUCache (originally by Nathan Schrenk). The object maintains a doubly-linked list of elements. When an element is accessed, it is promoted to the head of the list. When space is needed, the element at the tail of the list (the least recently used element) is evicted.

Index

Package Files

lru_cache.go

type Item Uses

type Item struct {
    Key   string
    Value Value
}

Item is what is stored in the cache

type LRUCache Uses

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

LRUCache is a typical LRU cache implementation. If the cache reaches the capacity, the least recently used item is deleted from the cache. Note the capacity is not the number of items, but the total sum of the Size() of each item.

func NewLRUCache Uses

func NewLRUCache(capacity int64) *LRUCache

NewLRUCache creates a new empty cache with the given capacity.

func (*LRUCache) Capacity Uses

func (lru *LRUCache) Capacity() int64

Capacity returns the cache maximum capacity.

func (*LRUCache) Clear Uses

func (lru *LRUCache) Clear()

Clear will clear the entire cache.

func (*LRUCache) Delete Uses

func (lru *LRUCache) Delete(key string) bool

Delete removes an entry from the cache, and returns if the entry existed.

func (*LRUCache) Evictions Uses

func (lru *LRUCache) Evictions() int64

Evictions returns the eviction count.

func (*LRUCache) Get Uses

func (lru *LRUCache) Get(key string) (v Value, ok bool)

Get returns a value from the cache, and marks the entry as most recently used.

func (*LRUCache) Items Uses

func (lru *LRUCache) Items() []Item

Items returns all the values for the cache, ordered from most recently used to last recently used.

func (*LRUCache) Keys Uses

func (lru *LRUCache) Keys() []string

Keys returns all the keys for the cache, ordered from most recently used to last recently used.

func (*LRUCache) Length Uses

func (lru *LRUCache) Length() int64

Length returns how many elements are in the cache

func (*LRUCache) Oldest Uses

func (lru *LRUCache) Oldest() (oldest time.Time)

Oldest returns the insertion time of the oldest element in the cache, or a IsZero() time if cache is empty.

func (*LRUCache) Peek Uses

func (lru *LRUCache) Peek(key string) (v Value, ok bool)

Peek returns a value from the cache without changing the LRU order.

func (*LRUCache) Set Uses

func (lru *LRUCache) Set(key string, value Value)

Set sets a value in the cache.

func (*LRUCache) SetCapacity Uses

func (lru *LRUCache) SetCapacity(capacity int64)

SetCapacity will set the capacity of the cache. If the capacity is smaller, and the current cache size exceed that capacity, the cache will be shrank.

func (*LRUCache) SetIfAbsent Uses

func (lru *LRUCache) SetIfAbsent(key string, value Value)

SetIfAbsent will set the value in the cache if not present. If the value exists in the cache, we don't set it.

func (*LRUCache) Size Uses

func (lru *LRUCache) Size() int64

Size returns the sum of the objects' Size() method.

func (*LRUCache) Stats Uses

func (lru *LRUCache) Stats() (length, size, capacity, evictions int64, oldest time.Time)

Stats returns a few stats on the cache.

func (*LRUCache) StatsJSON Uses

func (lru *LRUCache) StatsJSON() string

StatsJSON returns stats as a JSON object in a string.

type Value Uses

type Value interface {
    // Size returns how big this value is. If you want to just track
    // the cache by number of objects, you may return the size as 1.
    Size() int
}

Value is the interface values that go into LRUCache need to satisfy

Package cache imports 4 packages (graph) and is imported by 6 packages. Updated 2019-06-12. Refresh now. Tools for package owners.