cache

package
v1.9.2 Latest Latest
Warning

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

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

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
	//
	// Parameters:
	//  * `key` - the key to retrieve
	//
	// Returns the value associated with key and a bool that is `false`
	// if the key was not found
	Get(key interface{}) (interface{}, bool)
	// Put puts a value in cache associated with key
	//
	// Parameters:
	//  * `key` - the key to put
	//  * `value` - the value to put
	Put(key interface{}, value interface{})
	// Delete deletes the cache entry associated with key
	//
	// Parameters:
	//  * `key` - the key to delete
	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

Parameters:

  • `capacity` - a positive integer indicating the max capacity of this cache

Returns the new allocated LRU Cache and an error

func (*LRUCache) Delete

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

Delete deletes the cache entry associated with key

Parameters:

  • `key` - the key to delete

func (*LRUCache) Get

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

Get returns the cache value associated with key

Parameters:

  • `key` - the key to retrieve

Returns the value associated with key and a bool that is `false` if the key was not found

func (*LRUCache) Put

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

Put puts a value in cache associated with key

Parameters:

  • `key` - the key to put
  • `value` - the value to put

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

Parameters:

  • `key` - the key to delete

func (*MapCache) Get

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

Get returns the cache value associated with key

Parameters:

  • `key` - the key to retrieve

Returns the value associated with key and a bool that is `false` if the key was not found

func (*MapCache) Put

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

Put puts a value in cache associated with key

Parameters:

  • `key` - the key to put
  • `value` - the value to put

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