cache

package
v21.11.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2022 License: Apache-2.0 Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	OptionOnMissKeyword        = "on_miss"
	OptionOnMissTimeoutKeyword = "on_miss_timeout"
)

Variables

This section is empty.

Functions

func MissEventOption added in v21.11.1

func MissEventOption(fn func() (Cacheable, fail.Error), timeout time.Duration) []data.ImmutableKeyValue

MissEventOption returns []data.ImmutableKeyValue options to use on cache miss with timeout

Types

type Cache

type Cache interface {
	Get(ctx context.Context, key string, options ...data.ImmutableKeyValue) (ce *Entry, xerr fail.Error)
	ReserveEntry(ctx context.Context, key string, timeout time.Duration) fail.Error
	CommitEntry(ctx context.Context, key string, content Cacheable) (ce *Entry, xerr fail.Error)
	FreeEntry(ctx context.Context, key string) fail.Error
	AddEntry(ctx context.Context, content Cacheable) (ce *Entry, xerr fail.Error)
}

Cache interface describing what a struct must implement to be considered as a cache

type Cacheable

type Cacheable interface {
	observer.Observable // FIXME: also return error

	Released() error  // Released tells cache handler the instance is no more used, giving a chance to free this instance from cache
	Destroyed() error // Destroyed tells cache handler the instance has been deleted and MUST be removed from cache
}

Cacheable is the interface a struct must satisfy to be able to be cached

type Entry

type Entry struct {
	observer.Observer
	// contains filtered or unexported fields
}

Entry is a struct containing information about a cache entry

func (*Entry) Content

func (ce *Entry) Content() interface{}

Content returns the content of the cache

func (*Entry) Key

func (ce *Entry) Key() string

Key returns the key of the cache entry

func (*Entry) LockContent

func (ce *Entry) LockContent() uint

LockContent increments the counter of use of cache entry

func (*Entry) LockCount

func (ce *Entry) LockCount() uint

LockCount returns the current count of locks of the content

func (*Entry) UnlockContent

func (ce *Entry) UnlockContent() uint

UnlockContent decrements the counter of use of cached entry

func (*Entry) UpdateContent added in v21.11.1

func (ce *Entry) UpdateContent(content Cacheable) fail.Error

UpdateContent updates the content of the Entry

type IdentifiableCache added in v21.11.1

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

IdentifiableCache contains the caches for objects that satisfy data.Identifiable interface

func NewIdentifiableCache added in v21.11.1

func NewIdentifiableCache(name string, store Store) (*IdentifiableCache, fail.Error)

NewIdentifiableCache initializes a new instance of IdentifiableCache

func (*IdentifiableCache) AddEntry added in v21.11.1

func (instance *IdentifiableCache) AddEntry(ctx context.Context, content Cacheable) (*Entry, fail.Error)

AddEntry ...

func (*IdentifiableCache) CommitEntry added in v21.11.1

func (instance *IdentifiableCache) CommitEntry(ctx context.Context, key string, content Cacheable) (*Entry, fail.Error)

CommitEntry confirms the entry in the cache with the content passed as parameter

func (*IdentifiableCache) FreeEntry added in v21.11.1

func (instance *IdentifiableCache) FreeEntry(ctx context.Context, key string) fail.Error

FreeEntry removes the reservation in cache

func (*IdentifiableCache) Get added in v21.11.1

func (instance *IdentifiableCache) Get(ctx context.Context, key string, options ...data.ImmutableKeyValue) (*Entry, fail.Error)

Get returns the content associated with key

func (*IdentifiableCache) ReserveEntry added in v21.11.1

func (instance *IdentifiableCache) ReserveEntry(ctx context.Context, key string, timeout time.Duration) fail.Error

ReserveEntry sets a cache entry to reserve the key and returns the Entry associated

type SingleCache added in v21.11.1

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

SingleCache proposes a cache of Cacheable

func NewSingleCache added in v21.11.1

func NewSingleCache(name string, store Store) (*SingleCache, fail.Error)

NewSingleCache initializes a new instance of SingleCache

func (*SingleCache) AddEntry added in v21.11.1

func (instance *SingleCache) AddEntry(ctx context.Context, content Cacheable) (ce *Entry, xerr fail.Error)

AddEntry ...

func (*SingleCache) CommitEntry added in v21.11.1

func (instance *SingleCache) CommitEntry(ctx context.Context, key string, content Cacheable) (ce *Entry, xerr fail.Error)

CommitEntry confirms the entry in the cache with the content passed as parameter

func (*SingleCache) FreeEntry added in v21.11.1

func (instance *SingleCache) FreeEntry(ctx context.Context, key string) fail.Error

FreeEntry removes the reservation in cache

func (*SingleCache) Get added in v21.11.1

func (instance *SingleCache) Get(ctx context.Context, key string, options ...data.ImmutableKeyValue) (ce *Entry, ferr fail.Error)

Get returns the content associated with key Without option OptionOnMissKeyword, Get will not try to fill the cahce, and behaves just like a way to search in cache if key exists returns:

  • *Entry, nil: found the entry corresponding to key
  • nil, *fail.ErrInvalidInstance: Get called from nil of null value of SingleCache
  • nil, *fail.ErrInvalidParameter: one of the parameter is wrong
  • nil, *fail.ErrInconsistentError: something is inconsistent in options
  • nil, *fail.ErrNotFoundError: no entry associated with 'key' in cache

func (*SingleCache) ReserveEntry added in v21.11.1

func (instance *SingleCache) ReserveEntry(ctx context.Context, key string, timeout time.Duration) fail.Error

ReserveEntry sets a cache entry to reserve the key and returns the Entry associated

type Store added in v21.11.1

type Store interface {
	observer.Observer

	Entry(ctx context.Context, key string) (*Entry, fail.Error)                     // returns a cached entry from its key
	Reserve(ctx context.Context, key string, timeout time.Duration) fail.Error      // reserve an entry in the cached
	Commit(ctx context.Context, key string, content Cacheable) (*Entry, fail.Error) // Commit fills a previously reserved entry by 'key' with 'content'
	Free(ctx context.Context, key string) fail.Error                                // frees a cached entry (removing the reservation from cached)
	Add(ctx context.Context, content Cacheable) (*Entry, fail.Error)                // adds a content in cache (doing Reserve+Commit in a whole with content ID as key)
}

Store interface describing what a struct must implement to be considered as a cache storage

func NewMapStore added in v21.11.1

func NewMapStore(name string) (Store, fail.Error)

NewMapStore creates a new cache storage based on map (thread-safe)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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