cache

package
v0.8.8 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2017 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrKeyNotFound gets returned when a specific key couldn't be found
	ErrKeyNotFound = errors.New("Key not found in cache")
	ErrItem        = errors.New("make item fail")
)

Functions

This section is empty.

Types

type CacheItem

type CacheItem struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewCacheItem

func NewCacheItem(key string, lifeSpan time.Duration, data []byte) *CacheItem

NewCacheItem returns a newly created CacheItem.

func (*CacheItem) CreatedOn

func (item *CacheItem) CreatedOn() time.Time

CreatedOn returns when this item was added to the cache.

func (*CacheItem) Data

func (item *CacheItem) Data() []byte

Data returns the value of this cached item.

func (*CacheItem) Key

func (item *CacheItem) Key() string

Key returns the key of this cached item.

func (*CacheItem) LifeSpan

func (item *CacheItem) LifeSpan() time.Duration

LifeSpan returns when this item was added to the cache.

func (*CacheItem) SetAboutToExpireCallback

func (item *CacheItem) SetAboutToExpireCallback(f func(interface{}))

SetAboutToExpireCallback before the item is about to be removed from the cache.

type CacheTable

type CacheTable struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewCacheTable

func NewCacheTable(table string) *CacheTable

func (*CacheTable) Add

func (table *CacheTable) Add(key string, liftSpan time.Duration, data []byte) error

func (*CacheTable) Del

func (table *CacheTable) Del(key string) error

func (*CacheTable) Exists

func (table *CacheTable) Exists(key string) (bool, []byte)

func (*CacheTable) NotFoundAdd

func (table *CacheTable) NotFoundAdd(key string, liftSpan time.Duration, data []byte) (bool, error)

func (*CacheTable) SetAboutToDeleteItemCallback

func (table *CacheTable) SetAboutToDeleteItemCallback(f func(*CacheItem))

SetAboutToDeleteItemCallback set Callback for an item is about to be removed from the cache.

func (*CacheTable) SetAddedItemCallback

func (table *CacheTable) SetAddedItemCallback(f func(*CacheItem))

SetAddedItemCallback set Callback for a new item is added to the cache.

type CacheTxs

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

func NewCacheTxs

func NewCacheTxs() *CacheTxs

NewCacheTxs returns a basic db instance

func (*CacheTxs) Add

func (ntc *CacheTxs) Add(tx *types.Transaction, chainIDs []byte) error

Add add new tx, at the same time we put tx to db

func (*CacheTxs) Del

func (ntc *CacheTxs) Del(tx *types.Transaction) error

Del del this tx from cache

func (*CacheTxs) Exists

func (ntc *CacheTxs) Exists(tx *types.Transaction) (bool, []byte)

Exists whether tx exists

func (*CacheTxs) NotFoundAdd

func (ntc *CacheTxs) NotFoundAdd(tx *types.Transaction, chainIDs []byte) (bool, error)

NotFoundAdd add tx if not exists, return if exists

type PersistItem

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

PersistItem

func NewPersistItem

func NewPersistItem() *PersistItem

NewPersistItem initialization

func (*PersistItem) Add

func (pi *PersistItem) Add(key string, value []byte) error

Add add new item

func (*PersistItem) Del

func (pi *PersistItem) Del(key string) error

Del delete the item from db

func (*PersistItem) Exists

func (pi *PersistItem) Exists(key string) (bool, []byte)

Exists whether key exist

Jump to

Keyboard shortcuts

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