cache

package
v1.19.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: MIT Imports: 2 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 struct {
	// contains filtered or unexported fields
}

Cache implements Store interface with a safe map

func CreateCache

func CreateCache(kfunc ObjectKeyFunc) *Cache

CreateCache create Cache object

func (*Cache) Add

func (c *Cache) Add(obj interface{}) error

Add inserts an item into the cache.

func (*Cache) Clear

func (c *Cache) Clear()

Clear will drop all data in Store

func (*Cache) Delete

func (c *Cache) Delete(obj interface{}) error

Delete removes an item from the cache.

func (*Cache) Get

func (c *Cache) Get(obj interface{}) (item interface{}, exists bool, err error)

Get returns the requested item

func (*Cache) GetByKey

func (c *Cache) GetByKey(key string) (item interface{}, exists bool, err error)

GetByKey returns the request item, or exists=false.

func (*Cache) List

func (c *Cache) List() []interface{}

List returns a list of all the items.

func (*Cache) ListKeys

func (c *Cache) ListKeys() []string

ListKeys returns a list of all the keys of the objects currently in the cache.

func (*Cache) Num

func (c *Cache) Num() int

Num will return data counts in Store

func (*Cache) Replace

func (c *Cache) Replace(list []interface{}) error

Replace use new list to replace data in Cache

func (*Cache) Update

func (c *Cache) Update(obj interface{}) error

Update sets an item in the cache to its updated state.

type DataNoExist

type DataNoExist struct {
	Obj interface{}
}

DataNoExist return when No data in Store

func (DataNoExist) Error

func (k DataNoExist) Error() string

Error return string info

type KeyError

type KeyError struct {
	Obj interface{}
	Err error
}

KeyError wrapper error return from ObjectKeyFunc

func (KeyError) Error

func (k KeyError) Error() string

Error return string info for KeyError

type ObjectKeyFunc

type ObjectKeyFunc func(obj interface{}) (string, error)

ObjectKeyFunc define make object to a uniq key

type Store

type Store interface {
	Add(obj interface{}) error
	Update(obj interface{}) error
	Delete(obj interface{}) error
	List() []interface{}
	ListKeys() []string
	Get(obj interface{}) (item interface{}, exists bool, err error)
	GetByKey(key string) (item interface{}, exists bool, err error)
	Num() int
	Clear()
	Replace([]interface{}) error
}

Store is storage interface

func NewCache

func NewCache(kfunc ObjectKeyFunc) Store

NewCache create cache with designated ObjectKeyFunc

Jump to

Keyboard shortcuts

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