cache

package
v0.1.22 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Set(key, value interface{}) (evicted bool)
	Contains(key interface{}) bool
	Get(key interface{}) (value interface{}, ok bool)
	Keys() []interface{}
	Len() int
	Purge()
	Remove(key interface{}) (present bool)
	Resize(size int) (evicted int)
	Updated() time.Time
	SetLogger(logger logger.Logger)
}

Cache wrapper to integrate any 3rd party implementation

type LRUCache

type LRUCache struct {
	*lru.Cache
	// contains filtered or unexported fields
}

LRUCache is thread-safe LAST READ USED Cache

func NewLruCache

func NewLruCache(size int, logger logger.Logger) (*LRUCache, error)

NewLruCache creates a new LRU instance

func (*LRUCache) Contains

func (lru *LRUCache) Contains(key interface{}) bool

Contains checks if a key is in the cache

func (*LRUCache) Get

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

Get looks up a key's value from the cache.

func (*LRUCache) Keys

func (lru *LRUCache) Keys() []interface{}

Keys returns a slice of the keys in the cache, from oldest to newest.

func (*LRUCache) Len

func (lru *LRUCache) Len() int

Len returns the number of items in the cache.

func (*LRUCache) Purge

func (lru *LRUCache) Purge()

Purge is used to completely clear the cache.

func (*LRUCache) Remove

func (lru *LRUCache) Remove(key interface{}) (present bool)

Remove removes the provided key from the cache.

func (*LRUCache) Resize

func (lru *LRUCache) Resize(size int) (evicted int)

Resize changes the cache size.

func (*LRUCache) Set

func (lru *LRUCache) Set(key interface{}, value interface{}) (evicted bool)

Set a new value if it is different from the previous one. Returns true if an eviction occurred.

func (*LRUCache) SetLogger

func (lru *LRUCache) SetLogger(logger logger.Logger)

SetLogger set logger

func (*LRUCache) Updated

func (lru *LRUCache) Updated() time.Time

Updated lastUpdate information

type Persistence

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

Persistence persist cache data to a storage

func NewPersistence

func NewPersistence(store storage.Storage, cache Cache, logger logger.Logger) Persistence

NewPersistence creates a new instance for persisting data

func (*Persistence) LoadFromStore

func (p *Persistence) LoadFromStore() error

LoadFromStore loads all stored data into specified cache

func (Persistence) SaveToStore

func (p Persistence) SaveToStore() error

SaveToStore saves data to declared storage only if last update is greater than persisted time

Jump to

Keyboard shortcuts

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