cache

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2021 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

View Source
const (
	// Discards the least recently used items first.
	LRU evictionPolicy = iota
	// Discards the least frequently used items first.
	LFU
)

Variables

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

Functions

This section is empty.

Types

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)
}

Cache is common interface of cache.

func NewCache

func NewCache(capacity int, policy evictionPolicy) Cache

NewCache returns cache with selected eviction policy.

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) 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) (interface{}, error)

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

func (*LRUCache) Set

func (c *LRUCache) Set(key string, value interface{}, 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