cache

package
v0.0.0-...-77b6ffe Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package cache provides interface and implementation of a cache algorithms.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache is a 'cache map'.

func NewCache

func NewCache(cacher Cacher) *Cache

NewCache creates a new 'cache map'. The cacher is optional and may be nil.

func (*Cache) Add

func (r *Cache) Add(key, value interface{}, blockNum uint64) bool

Add sets k,v data and the blockNum when inserting into cache. It returns true if the data pair is inserted into the cache successfully.

func (*Cache) Close

func (r *Cache) Close() error

Purge purges the 'cache map' and forcefully releases all 'cache node'.

func (*Cache) Delete

func (r *Cache) Delete(key interface{}) bool

Delete removes and ban 'cache node' with the given namespace and key. A banned 'cache node' will never inserted into the 'cache tree'. Ban only attributed to the particular 'cache node', so when a 'cache node' is recreated it will not be banned.

Delete return true is such 'cache node' exist.

func (*Cache) EvictWithStrategy

func (r *Cache) EvictWithStrategy(strategy func(blockNum uint64) bool) int

func (*Cache) Get

func (r *Cache) Get(key interface{}) (val interface{}, blockNum uint64)

Get gets the value with the given key.

func (*Cache) Nodes

func (r *Cache) Nodes() int

Nodes returns number of 'cache node' in the map.

func (*Cache) Purge

func (r *Cache) Purge()

EvictAll evicts all 'cache node'. This will simply call Cacher.EvictAll.

func (*Cache) Size

func (r *Cache) Size() int

Size returns sums of 'cache node' size in the map.

type Cacher

type Cacher interface {

	// Promote promotes the 'cache node'.
	Promote(n *Node)

	// Ban evicts the 'cache node' and prevent subsequent 'promote'.
	Ban(n *Node)

	// Evict evicts the 'cache node'.
	Evict(n *Node)

	// EvictWithStrategy evicts 'cache node' with a given strategy.
	//
	// It returns the number of the evicted `cache node`
	EvictWithStrategy(st func(blockNum uint64) bool) int

	// EvictAll evicts all 'cache node'.
	EvictAll()

	// Close closes the 'cache tree'
	Close() error
}

Cacher provides interface to implements a caching functionality. An implementation must be safe for concurrent use.

func NewLBN

func NewLBN() Cacher

type Handle

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

Handle is a 'cache handle' of a 'cache node'.

func (*Handle) Release

func (h *Handle) Release()

Release releases this 'cache handle'. It is safe to call release multiple times.

func (*Handle) Value

func (h *Handle) Value() interface{}

Value returns the value of the 'cache node'.

type Node

type Node struct {
	CacheData unsafe.Pointer
	// contains filtered or unexported fields
}

Node is a 'cache node'.

func (*Node) GetHandle

func (n *Node) GetHandle() *Handle

GetHandle returns an handle for this 'cache node'.

func (*Node) Key

func (n *Node) Key() interface{}

Key returns this 'cache node' key.

func (*Node) Ref

func (n *Node) Ref() int32

Ref returns this 'cache node' ref counter.

func (*Node) Size

func (n *Node) Size() int

Size returns this 'cache node' size.

func (*Node) Value

func (n *Node) Value() interface{}

Value returns this 'cache node' value.

Jump to

Keyboard shortcuts

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