lrucache

package
v0.0.0-...-7e31768 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2017 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var (
	PluginConfig = &lrucacheConfig{
		done: make(chan struct{}),
	}
)

Config ...

Functions

This section is empty.

Types

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.

Directories

Path Synopsis
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.
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.

Jump to

Keyboard shortcuts

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