{"modulePath":"github.com/CS-SI/SafeScale/v21","version":"v21.11.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package cache\n\n## Constants\n\n```go\nconst (\n\tOptionOnMissKeyword        = \"on_miss\"\n\tOptionOnMissTimeoutKeyword = \"on_miss_timeout\"\n)\n```\n\n## Functions\n\n```go\nfunc MissEventOption(fn func() (Cacheable, fail.Error), timeout time.Duration) []data.ImmutableKeyValue\n```\nMissEventOption returns \\[]data.ImmutableKeyValue options to use on cache miss with timeout\n\n## Types\n\n```go\ntype Cache interface {\n\tGet(ctx context.Context, key string, options ...data.ImmutableKeyValue) (ce *Entry, xerr fail.Error)\n\tReserveEntry(ctx context.Context, key string, timeout time.Duration) fail.Error\n\tCommitEntry(ctx context.Context, key string, content Cacheable) (ce *Entry, xerr fail.Error)\n\tFreeEntry(ctx context.Context, key string) fail.Error\n\tAddEntry(ctx context.Context, content Cacheable) (ce *Entry, xerr fail.Error)\n}\n```\nCache interface describing what a struct must implement to be considered as a cache\n\n```go\ntype Cacheable interface {\n\tobserver.Observable // FIXME: also return error\n\n\tReleased() error  // Released tells cache handler the instance is no more used, giving a chance to free this instance from cache\n\tDestroyed() error // Destroyed tells cache handler the instance has been deleted and MUST be removed from cache\n}\n```\nCacheable is the interface a struct must satisfy to be able to be cached\n\n```go\ntype Entry struct {\n\tobserver.Observer\n\t// contains filtered or unexported fields\n}\n```\nEntry is a struct containing information about a cache entry\n\n```go\nfunc (ce *Entry) Content() interface{}\n```\nContent returns the content of the cache\n\n```go\nfunc (ce *Entry) Key() string\n```\nKey returns the key of the cache entry\n\n```go\nfunc (ce *Entry) LockContent() uint\n```\nLockContent increments the counter of use of cache entry\n\n```go\nfunc (ce *Entry) LockCount() uint\n```\nLockCount returns the current count of locks of the content\n\n```go\nfunc (ce *Entry) UnlockContent() uint\n```\nUnlockContent decrements the counter of use of cached entry\n\n```go\nfunc (ce *Entry) UpdateContent(content Cacheable) fail.Error\n```\nUpdateContent updates the content of the Entry\n\n```go\ntype IdentifiableCache struct {\n\t// contains filtered or unexported fields\n}\n```\nIdentifiableCache contains the caches for objects that satisfy data.Identifiable interface\n\n```go\nfunc NewIdentifiableCache(name string, store Store) (*IdentifiableCache, fail.Error)\n```\nNewIdentifiableCache initializes a new instance of IdentifiableCache\n\n```go\nfunc (instance *IdentifiableCache) AddEntry(ctx context.Context, content Cacheable) (*Entry, fail.Error)\n```\nAddEntry ...\n\n```go\nfunc (instance *IdentifiableCache) CommitEntry(ctx context.Context, key string, content Cacheable) (*Entry, fail.Error)\n```\nCommitEntry confirms the entry in the cache with the content passed as parameter\n\n```go\nfunc (instance *IdentifiableCache) FreeEntry(ctx context.Context, key string) fail.Error\n```\nFreeEntry removes the reservation in cache\n\n```go\nfunc (instance *IdentifiableCache) Get(ctx context.Context, key string, options ...data.ImmutableKeyValue) (*Entry, fail.Error)\n```\nGet returns the content associated with key\n\n```go\nfunc (instance *IdentifiableCache) ReserveEntry(ctx context.Context, key string, timeout time.Duration) fail.Error\n```\nReserveEntry sets a cache entry to reserve the key and returns the Entry associated\n\n```go\ntype SingleCache struct {\n\t// contains filtered or unexported fields\n}\n```\nSingleCache proposes a cache of Cacheable\n\n```go\nfunc NewSingleCache(name string, store Store) (*SingleCache, fail.Error)\n```\nNewSingleCache initializes a new instance of SingleCache\n\n```go\nfunc (instance *SingleCache) AddEntry(ctx context.Context, content Cacheable) (ce *Entry, xerr fail.Error)\n```\nAddEntry ...\n\n```go\nfunc (instance *SingleCache) CommitEntry(ctx context.Context, key string, content Cacheable) (ce *Entry, xerr fail.Error)\n```\nCommitEntry confirms the entry in the cache with the content passed as parameter\n\n```go\nfunc (instance *SingleCache) FreeEntry(ctx context.Context, key string) fail.Error\n```\nFreeEntry removes the reservation in cache\n\n```go\nfunc (instance *SingleCache) Get(ctx context.Context, key string, options ...data.ImmutableKeyValue) (ce *Entry, ferr fail.Error)\n```\nGet 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:\n\n  - \\*Entry, nil: found the entry corresponding to key\n  - nil, \\*fail.ErrInvalidInstance: Get called from nil of null value of SingleCache\n  - nil, \\*fail.ErrInvalidParameter: one of the parameter is wrong\n  - nil, \\*fail.ErrInconsistentError: something is inconsistent in options\n  - nil, \\*fail.ErrNotFoundError: no entry associated with 'key' in cache\n\n```go\nfunc (instance *SingleCache) ReserveEntry(ctx context.Context, key string, timeout time.Duration) fail.Error\n```\nReserveEntry sets a cache entry to reserve the key and returns the Entry associated\n\n```go\ntype Store interface {\n\tobserver.Observer\n\n\tEntry(ctx context.Context, key string) (*Entry, fail.Error)                     // returns a cached entry from its key\n\tReserve(ctx context.Context, key string, timeout time.Duration) fail.Error      // reserve an entry in the cached\n\tCommit(ctx context.Context, key string, content Cacheable) (*Entry, fail.Error) // Commit fills a previously reserved entry by 'key' with 'content'\n\tFree(ctx context.Context, key string) fail.Error                                // frees a cached entry (removing the reservation from cached)\n\tAdd(ctx context.Context, content Cacheable) (*Entry, fail.Error)                // adds a content in cache (doing Reserve+Commit in a whole with content ID as key)\n}\n```\nStore interface describing what a struct must implement to be considered as a cache storage\n\n```go\nfunc NewMapStore(name string) (Store, fail.Error)\n```\nNewMapStore creates a new cache storage based on map (thread-safe)\n\n","path":"github.com/CS-SI/SafeScale/v21/lib/utils/data/cache","name":"cache","synopsis":"","isRedistributable":true}
