cache

package
v1.1.82 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 11 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTopic

func CreateTopic(topic string) (notification.PubSub, error)

CreateTopic - create a new PubSub for a cache item

func CreateTopicWithInitData

func CreateTopicWithInitData(topic string, initData interface{}) (notification.PubSub, error)

CreateTopicWithInitData - create a new PubSub with an item that will be cached, initialize it as well

func GetPubSub

func GetPubSub(topic string) (notification.PubSub, error)

GetPubSub - find a PubSub by topic name

func RemoveTopic

func RemoveTopic(topic string) error

RemoveTopic - removes a PubSub topic and cleans up it's cache

func SetCache

func SetCache(c Cache)

SetCache - sets the global cache

Types

type Cache

type Cache interface {
	Get(key string) (interface{}, error)
	GetItem(key string) (*Item, error)
	GetBySecondaryKey(secondaryKey string) (interface{}, error)
	GetItemBySecondaryKey(secondaryKey string) (*Item, error)
	GetForeignKeys() []string
	GetItemsByForeignKey(foreignKey string) ([]*Item, error)
	GetKeys() []string
	HasItemChanged(key string, data interface{}) (bool, error)
	HasItemBySecondaryKeyChanged(secondaryKey string, data interface{}) (bool, error)
	Set(key string, data interface{}) error
	SetWithSecondaryKey(key string, secondaryKey string, data interface{}) error
	SetWithForeignKey(key string, foreignKey string, data interface{}) error
	SetSecondaryKey(key string, secondaryKey string) error
	SetForeignKey(key string, foreignKey string) error
	Delete(key string) error
	DeleteBySecondaryKey(secondaryKey string) error
	DeleteSecondaryKey(secondaryKey string) error
	DeleteForeignKey(foreignKey string) error
	DeleteItemsByForeignKey(foreignKey string) error
	Flush()
	Save(path string) error
	Load(path string) error
}

Cache - Interface for managing the proxy cache

func GetCache

func GetCache() Cache

GetCache - get the global cache object

func Load

func Load(path string) Cache

Load - create a new cache object and load saved data

func LoadFromBuffer

func LoadFromBuffer(buffer []byte) Cache

LoadFromBuffer - create a new cache object and loads the data from buffer

func New

func New() Cache

New - create a new cache object

type GetItem

type GetItem interface {
	Get(key string) (interface{}, error)
}

GetItem interface for getting a single item from a cache.

type Item

type Item struct {
	Object          interface{}     `json:"data"`
	UpdateTime      int64           `json:"updateTime"`
	Hash            uint64          `json:"hash"`
	SecondaryKeys   map[string]bool `json:"secondaryKeys"` // keep track of secondary keys for clean up
	ForeignKey      string          `json:"foreignKey"`
	ContainsPointer bool            `json:"containsPointer"` // does item contain a pointer
}

Item - a cached item

func (*Item) GetHash

func (i *Item) GetHash() uint64

GetHash - returns the hash of the object in this cache item

func (*Item) GetObject

func (i *Item) GetObject() interface{}

GetObject - returns the object saved in this cache item

func (*Item) GetUpdateTime

func (i *Item) GetUpdateTime() int64

GetUpdateTime - returns the epoch time that this cache item was updated

type MockCache

type MockCache struct {
}

MockCache a mock cache

func (MockCache) Delete

func (m MockCache) Delete(_ string) error

Delete -

func (MockCache) DeleteBySecondaryKey

func (m MockCache) DeleteBySecondaryKey(_ string) error

DeleteBySecondaryKey -

func (MockCache) DeleteForeignKey

func (m MockCache) DeleteForeignKey(_ string) error

DeleteForeignKey -

func (MockCache) DeleteItemsByForeignKey

func (m MockCache) DeleteItemsByForeignKey(_ string) error

DeleteItemsByForeignKey -

func (MockCache) DeleteSecondaryKey

func (m MockCache) DeleteSecondaryKey(_ string) error

DeleteSecondaryKey -

func (MockCache) Flush

func (m MockCache) Flush()

Flush -

func (MockCache) Get

func (m MockCache) Get(_ string) (interface{}, error)

Get -

func (MockCache) GetBySecondaryKey

func (m MockCache) GetBySecondaryKey(_ string) (interface{}, error)

GetBySecondaryKey -

func (MockCache) GetForeignKeys

func (m MockCache) GetForeignKeys() []string

GetForeignKeys -

func (MockCache) GetItem

func (m MockCache) GetItem(_ string) (*Item, error)

GetItem -

func (MockCache) GetItemBySecondaryKey

func (m MockCache) GetItemBySecondaryKey(_ string) (*Item, error)

GetItemBySecondaryKey -

func (MockCache) GetItemsByForeignKey

func (m MockCache) GetItemsByForeignKey(_ string) ([]*Item, error)

GetItemsByForeignKey -

func (MockCache) GetKeys

func (m MockCache) GetKeys() []string

GetKeys -

func (MockCache) HasItemBySecondaryKeyChanged

func (m MockCache) HasItemBySecondaryKeyChanged(_ string, _ interface{}) (bool, error)

HasItemBySecondaryKeyChanged -

func (MockCache) HasItemChanged

func (m MockCache) HasItemChanged(_ string, _ interface{}) (bool, error)

HasItemChanged -

func (MockCache) Load

func (m MockCache) Load(_ string) error

Load -

func (MockCache) Save

func (m MockCache) Save(_ string) error

Save -

func (MockCache) Set

func (m MockCache) Set(_ string, _ interface{}) error

Set -

func (MockCache) SetForeignKey

func (m MockCache) SetForeignKey(_ string, _ string) error

SetForeignKey -

func (MockCache) SetSecondaryKey

func (m MockCache) SetSecondaryKey(_ string, _ string) error

SetSecondaryKey -

func (MockCache) SetWithForeignKey

func (m MockCache) SetWithForeignKey(_ string, _ string, _ interface{}) error

SetWithForeignKey -

func (MockCache) SetWithSecondaryKey

func (m MockCache) SetWithSecondaryKey(_ string, _ string, _ interface{}) error

SetWithSecondaryKey -

Jump to

Keyboard shortcuts

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