cache

package
v0.0.0-...-e5673ba Latest Latest
Warning

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

Go to latest
Published: May 7, 2023 License: MIT Imports: 3 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 interface {
	// Get returns the cache value associated with key
	Get(key interface{}) (interface{}, bool)
	// Put puts a value in cache associated with key
	Put(key interface{}, value interface{})
	// Delete deletes the cache entry associated with key
	Delete(key interface{})
	// ToMap returns the current cache entries copied into a map
	ToMap() map[interface{}]interface{}
}

Cache represents a key-value storage where to put cached data.

type LRUCache

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

LRUCache is a Least Recently Used (LRU) Cache with given capacity.

func NewLRUCache

func NewLRUCache(capacity int) (c *LRUCache, err error)

NewLRUCache creates a new Least Recently Used (LRU) Cache.

func (*LRUCache) Delete

func (c *LRUCache) Delete(key interface{})

Delete deletes the cache entry associated with key.

func (*LRUCache) Get

func (c *LRUCache) Get(key interface{}) (value interface{}, ok bool)

Get returns the cache value associated with key.

func (*LRUCache) Put

func (c *LRUCache) Put(key interface{}, value interface{})

Put puts a value in cache associated with key.

func (*LRUCache) ToMap

func (c *LRUCache) ToMap() map[interface{}]interface{}

ToMap returns the current cache entries copied into a map.

type MapCache

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

MapCache is a cache backed by a map.

func NewMapCache

func NewMapCache() *MapCache

NewMapCache creates a new cache backed by a map.

func (*MapCache) Delete

func (c *MapCache) Delete(key interface{})

Delete deletes the cache entry associated with key.

func (*MapCache) Get

func (c *MapCache) Get(key interface{}) (value interface{}, ok bool)

Get returns the cache value associated with key.

func (*MapCache) Put

func (c *MapCache) Put(key interface{}, value interface{})

Put puts a value in cache associated with key.

func (*MapCache) ToMap

func (c *MapCache) ToMap() map[interface{}]interface{}

ToMap returns the current cache entries copied into a map.

Jump to

Keyboard shortcuts

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