tearc

package module
v0.0.0-...-b6677e2 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Overview

Package tearc provides a sharded caching data structure with sliding frame (e.g. timing) evictions and adaptive replacement caching. Its goal is to keep as few high-security objects (private keys) in memory as possible. Items are either evicted when chosen by page replacement (ARC) or at latest when their eviction time has come (a Go heap with sliding frames reaches it).

This results in a caching data structure that has at max n-items chosen by adaptive replacement caching, but fully clears its memory after the configured eviction time. The eviction time resets after every usage (Get) of the cached item.

tearc internally uses sharded caches to minimize mutex contention. This performs slightly worse on small caches, but improves stable performance in more congested times.

tearc stands for Timed-Eviction-Adaptive-Replacement-Cache

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BucketConfig

type BucketConfig struct {
	// MinTick is the minimum amount of time between bucket reaper runs.
	// For example: 1 * time.Second
	MinTick time.Duration
	// MaxTick is the maximum amount of time between bucket reaper runs.
	// For example: 10 * time.Second
	MaxTick time.Duration
}

type Cache

type Cache interface {
	Get(key string, loadInfo interface{}) (interface{}, error)
	Close()
}

Cache represents a single tearc instance

func NewCache

func NewCache(size int, shards int, loader LoaderFunc, evicted EvictedFunc, config *BucketConfig, log logger.Logger) (Cache, error)

NewCache creates a new tearc instance

type EvictedFunc

type EvictedFunc func(key string)

EvictedFunc is an information callback that is called after an item has been evicted from the cache.

type LoaderFunc

type LoaderFunc func(key string, info interface{}) (value interface{}, evictIn time.Duration, err error)

LoaderFunc represents a callback to load a non-existing value into the cache. info is the loadInfo object passed to Cache.Get.

Jump to

Keyboard shortcuts

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