gocql: github.com/gocql/gocql/internal/lru Index | Files

package lru

import "github.com/gocql/gocql/internal/lru"

Package lru implements an LRU cache.

Index

Package Files

lru.go

type Cache Uses

type Cache struct {
    // MaxEntries is the maximum number of cache entries before
    // an item is evicted. Zero means no limit.
    MaxEntries int

    // OnEvicted optionally specifies a callback function to be
    // executed when an entry is purged from the cache.
    OnEvicted func(key string, value interface{})
    // contains filtered or unexported fields
}

Cache is an LRU cache. It is not safe for concurrent access.

This cache has been forked from github.com/golang/groupcache/lru, but specialized with string keys to avoid the allocations caused by wrapping them in interface{}.

func New Uses

func New(maxEntries int) *Cache

New creates a new Cache. If maxEntries is zero, the cache has no limit and it's assumed that eviction is done by the caller.

func (*Cache) Add Uses

func (c *Cache) Add(key string, value interface{})

Add adds a value to the cache.

func (*Cache) Get Uses

func (c *Cache) Get(key string) (value interface{}, ok bool)

Get looks up a key's value from the cache.

func (*Cache) Len Uses

func (c *Cache) Len() int

Len returns the number of items in the cache.

func (*Cache) Remove Uses

func (c *Cache) Remove(key string) bool

Remove removes the provided key from the cache.

func (*Cache) RemoveOldest Uses

func (c *Cache) RemoveOldest()

RemoveOldest removes the oldest item from the cache.

Package lru imports 1 packages (graph) and is imported by 4 packages. Updated 2017-03-10. Refresh now. Tools for package owners.