ttlcache

package module
v0.0.0-...-3c85255 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2016 License: MIT Imports: 3 Imported by: 1

README

TTLCAche - LRU cache with TTL

Build Status Coverage Status GoDoc

TTLCache is based on the implementation design of golang's groupcache lru, with cache entry TTL control. A expired cache entry is preferred for cache eviction. When there is no expired entry, LRU principle takes effect. Cache Gets don't affect cache entry TTL.

It is thread-safe by a simple mutex lock.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EvictCallback

type EvictCallback func(key string, value interface{})

type LRU

type LRU struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

LRU cache with ttl

func NewLRU

func NewLRU(size int, defaultTTL time.Duration, onEvict EvictCallback) *LRU

NewLRU returns a new LRU cache.

func (*LRU) Get

func (c *LRU) Get(key string) (value interface{}, stale bool)

Get returns the cached value index by key. Return an additional boolean value indicating whether the returned element is stale

func (*LRU) Remove

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

Remove removes the element cached by key. Return a boolean value for whether a value is deleted.

func (*LRU) Set

func (c *LRU) Set(key string, value interface{}, ttl time.Duration) bool

Set sets a value with key into the cache. Returns a boolean value indicating whether a new element is created.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL