Documentation ¶
Index ¶
- Constants
- func MissEventOption(fn func() (Cacheable, fail.Error), timeout time.Duration) []data.ImmutableKeyValue
- type Cache
- type Cacheable
- type Entry
- type IdentifiableCache
- func (instance *IdentifiableCache) AddEntry(ctx context.Context, content Cacheable) (*Entry, fail.Error)
- func (instance *IdentifiableCache) CommitEntry(ctx context.Context, key string, content Cacheable) (*Entry, fail.Error)
- func (instance *IdentifiableCache) FreeEntry(ctx context.Context, key string) fail.Error
- func (instance *IdentifiableCache) Get(ctx context.Context, key string, options ...data.ImmutableKeyValue) (*Entry, fail.Error)
- func (instance *IdentifiableCache) ReserveEntry(ctx context.Context, key string, timeout time.Duration) fail.Error
- type SingleCache
- func (instance *SingleCache) AddEntry(ctx context.Context, content Cacheable) (ce *Entry, xerr fail.Error)
- func (instance *SingleCache) CommitEntry(ctx context.Context, key string, content Cacheable) (ce *Entry, xerr fail.Error)
- func (instance *SingleCache) FreeEntry(ctx context.Context, key string) fail.Error
- func (instance *SingleCache) Get(ctx context.Context, key string, options ...data.ImmutableKeyValue) (ce *Entry, ferr fail.Error)
- func (instance *SingleCache) ReserveEntry(ctx context.Context, key string, timeout time.Duration) fail.Error
- type Store
Constants ¶
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 ¶
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) LockContent ¶
LockContent increments the counter of use of cache entry
func (*Entry) UnlockContent ¶
UnlockContent decrements the counter of use of cached 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) 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) 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