cache

package
v1.4.6 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BehaviorOption added in v1.2.18

type BehaviorOption int
const (
	// StrictExpiry sets the behavior so that an expired item will never be returned by the cache.
	//
	// The default behavior is that items are returned until they have been purged from the cache by an
	// synchronous reaper
	// NOTE: see issue https://github.com/hyperledger/firefly-common/issues/85 on operation of the async reaper.
	StrictExpiry BehaviorOption = iota

	// TTLFromInitialAdd sets the behavior so that the time-to-live for a cache entry is set when
	// it is added, and not extended when the item is accessed.
	// This is useful if you have code that wants to rely on a cache-miss as a way to force regular
	// synchronization of cached data with a remote source of truth
	//
	// The default behavior is that the TTL is extended each time a cache entry is accessed.
	// This is useful if you're managing the cache such that the data inside it is always valid,
	// and want to keep the most frequently accessed data in the cache indefinitely.
	TTLFromInitialAdd
)

type CCache

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

func (*CCache) Delete

func (c *CCache) Delete(key string) bool

func (*CCache) Get

func (c *CCache) Get(key string) interface{}

func (*CCache) GetInt

func (c *CCache) GetInt(key string) int

func (*CCache) GetInt64

func (c *CCache) GetInt64(key string) int64

func (*CCache) GetString

func (c *CCache) GetString(key string) string

func (*CCache) IsEnabled

func (c *CCache) IsEnabled() bool

func (*CCache) Set

func (c *CCache) Set(key string, val interface{})

func (*CCache) SetInt

func (c *CCache) SetInt(key string, val int)

func (*CCache) SetInt64

func (c *CCache) SetInt64(key string, val int64)

func (*CCache) SetString

func (c *CCache) SetString(key string, val string)

type CInterface

type CInterface interface {
	IsEnabled() bool
	Delete(key string) bool

	Get(key string) interface{}
	Set(key string, val interface{})

	GetString(key string) string
	SetString(key string, val string)

	GetInt(key string) int
	SetInt(key string, val int)

	GetInt64(key string) int64
	SetInt64(key string, val int64)
}

CInterface contains functions a cache instance need to provide

func NewUmanagedCache

func NewUmanagedCache(ctx context.Context, sizeLimit int64, ttl time.Duration) CInterface

should only be used for testing purpose

type Manager

type Manager interface {
	// Get a cache by name, if a cache already exists with the same name, it will be returned as is without checking maxSize, ttl and enabled matches
	GetCache(ctx context.Context, namespace, name string, maxSize int64, ttl time.Duration, enabled bool, behaviorOptions ...BehaviorOption) (CInterface, error)
	ListCacheNames(namespace string) []string
	ResetCaches(namespace string)
	IsEnabled() bool
}

Manager contains functions to manage cache instances. It provides functions for creating new cache instances and list all of the names of existing cache instances Each cache instance has unique name and its own cache size and TTL configuration.

func NewCacheManager

func NewCacheManager(ctx context.Context, enabled bool) Manager

Jump to

Keyboard shortcuts

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