badgerlrucache

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: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

badgerCache implements LRU cache using BadgerDB as high-performant, embedded k/v store.

func (*Cache) Add

func (c *Cache) Add(key, val []byte)

Add implements LRUCache.Add.

func (*Cache) Get

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

Get implements LRUCache.Get.

func (*Cache) Len

func (c *Cache) Len() int

Len implements LRUCache.Len.

type LRUCache

type LRUCache interface {
	// Add caches value for key. If cache is full (not part of the
	// interface), oldest records are dropped to make room.
	Add(key, value []byte)
	// Get retrieves value corresponding to key from cache if present.
	// Returns false in second argument if no value found or any other
	// error.
	Get(key []byte) ([]byte, bool)
	// Len returns number of values currently cached.
	Len() int
}

LRUCache defines operations on a standard LRU cache. All operations are meant to be thread-safe.

func NewLRUCache

func NewLRUCache(db *badger.DB, maxEntries int, ttl time.Duration) LRUCache

NewLRUCache returns new cache store.

func NewSimpleLRUCache

func NewSimpleLRUCache(maxEntries int, ttl time.Duration) LRUCache

NewSimpleLRUCache returns new in-memory cache of size maxEntries and with global ttl (records that are older than ttl are assumed to be missing and discarded).

Jump to

Keyboard shortcuts

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