cache

package module
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2022 License: Apache-2.0, Apache-2.0 Imports: 4 Imported by: 2

README

ttlcache Go Reference

Cache library with configurable eviction policy, supported LFU and LRU.

Install

$ go get github.com/moeryomenko/ttlcache

License

ttlcache is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and/or LICENSE-MIT for details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("key not found")

Functions

This section is empty.

Types

type ARCCache added in v0.1.5

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

ARCCache is improved LRU cache, that tracks both recency and frequency of use. See: https://ieeexplore.ieee.org/document/1297303.

func (*ARCCache) Get added in v0.1.5

func (c *ARCCache) Get(key string) (any, error)

func (*ARCCache) Remove added in v0.1.6

func (c *ARCCache) Remove(key string) error

func (*ARCCache) Set added in v0.1.5

func (c *ARCCache) Set(key string, value any, expiration time.Duration) error

type Cache

type Cache interface {
	// Set inserts or updates the specified key-value pair with an expiration time.
	Set(key string, value interface{}, expiry time.Duration) error
	// Get returns the value for specified key if it is present in the cache.
	Get(key string) (interface{}, error)
	// Remove removes item from cache by given key.
	Remove(key string) error
}

Cache is common interface of cache.

func NewCache

func NewCache(capacity int, policy EvictionPolicy) Cache

NewCache returns cache with selected eviction policy.

type EvictionPolicy added in v0.1.4

type EvictionPolicy int
const (
	// Discards the least recently used items first.
	LRU EvictionPolicy = iota
	// Discards the least frequently used items first.
	LFU
	// Adaptive replacement cache policy.
	ARC
)

type LFUCache

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

func (*LFUCache) Get

func (c *LFUCache) Get(key string) (interface{}, error)

Get returns the value for specified key if it is present in the cache.

func (*LFUCache) Remove added in v0.1.6

func (c *LFUCache) Remove(key string) error

func (*LFUCache) Set

func (c *LFUCache) Set(key string, value interface{}, expiration time.Duration) error

Set inserts or updates the specified key-value pair with an expiration time.

type LRUCache

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

func (*LRUCache) Get

func (c *LRUCache) Get(key string) (any, error)

Get returns the value for specified key if it is present in the cache.

func (*LRUCache) Len added in v0.1.5

func (c *LRUCache) Len() int

func (*LRUCache) Remove added in v0.1.5

func (c *LRUCache) Remove(key string) error

func (*LRUCache) Set

func (c *LRUCache) Set(key string, value any, expiration time.Duration) error

Set inserts or updates the specified key-value pair with an expiration time.

Jump to

Keyboard shortcuts

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