...

Package lrucache

import "github.com/die-net/lrucache"
Overview
Index
Subdirectories

Overview ▾

Package lrucache provides a byte-size-limited implementation of httpcache.Cache that stores data in memory.

type LruCache

type LruCache struct {
    MaxSize int64
    MaxAge  int64
    // contains filtered or unexported fields
}

LruCache is a thread-safe, in-memory httpcache.Cache that evicts the least recently used entries from memory when either MaxSize (in bytes) limit would be exceeded or (if set) the entries are older than MaxAge (in seconds). Use the New constructor to create one.

func New

func New(maxSize int64, maxAge int64) *LruCache

New creates an LruCache that will restrict itself to maxSize bytes of memory. If maxAge > 0, entries will also be expired after maxAge seconds.

func (*LruCache) Delete

func (c *LruCache) Delete(key string)

Delete removes the value associated with a key.

func (*LruCache) Get

func (c *LruCache) Get(key string) ([]byte, bool)

Get returns the []byte representation of a cached response and a bool set to true if the key was found.

func (*LruCache) Set

func (c *LruCache) Set(key string, value []byte)

Set stores the []byte representation of a response for a given key.

func (*LruCache) Size

func (c *LruCache) Size() int64

Size returns the estimated current memory usage of LruCache.

Subdirectories

Name Synopsis
..
twotier Package twotier provides a wrapper for two httpcache.Cache instances, allowing you to use both a small and fast cache for popular objects and fall back to a larger and slower cache for less popular ones.