Documentation
¶
Overview ¶
Package memstore provides in-memory data store implementation.
Store ¶
A Store provides in-memory key:value cache that expires after defined duration of time. That duration is defined when a new instance is initialized calling 'memstore.New()' function and it is used to all new stored values.
The Store can manage an application context. Creating an application context its the recommended way to avoid global variables and strict the access to your variables to selected functions.
The lifetime for new values and/or existing values can be modified calling 'SetLifetime()'. The new expiration time will be automatically updated as specified by the scope parameter.
The expiration behaviour can be changed calling 'SetTransient()' to define whether the lifetime of stored value is fixed (transient) or is extended when it is read or written (non-transient).
Index ¶
- type Store
- func (s *Store) Add(key string, value interface{}) error
- func (s *Store) Count() (int, error)
- func (s *Store) Decrement(key string) (int, error)
- func (s *Store) DecrementBy(key string, value int) (int, error)
- func (s *Store) Delete(key string) error
- func (s *Store) Flush() error
- func (s *Store) Get(key string, ref interface{}) error
- func (s *Store) Increment(key string) (int, error)
- func (s *Store) IncrementBy(key string, value int) (int, error)
- func (s *Store) Set(key string, value interface{}) error
- func (s *Store) SetLifetime(d time.Duration, scope data.LifetimeScope) error
- func (s *Store) SetTransient(value bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
A Store provides in-memory key:value cache that expires after defined duration of time.
It is a implementation of Store interface.
func New ¶
New creates a new instance of in-memory Store and defines the default lifetime for new stored items.
If it is specified to not transient then the stored items lifetime are renewed when it is read or written; Otherwise, it is never renewed.
func (*Store) Add ¶
Add adds a new key:value to current store.
Errors: DuplicatedKeyError when requested key already exists.
func (*Store) Decrement ¶
Decrement atomically gets the value stored by specified key and decrements it by one. If the key does not exist, it is created.
Errors: InvalidTypeError when the value stored at key is not integer.
func (*Store) DecrementBy ¶
DecrementBy atomically gets the value stored by specified key and decrements it by value. If the key does not exist, it is created.
Errors: InvalidTypeError when the value stored at key is not integer.
func (*Store) Delete ¶
Delete deletes the specified key:value.
Errors: InvalidKeyError when requested key could not be found.
func (*Store) Get ¶
Get gets the value stored by specified key.
Errors: InvalidKeyError when requested key could not be found.
func (*Store) Increment ¶
Increment atomically gets the value stored by specified key and increments it by one. If the key does not exist, it is created.
Errors: InvalidTypeError when the value stored at key is not integer.
func (*Store) IncrementBy ¶
IncrementBy atomically gets the value stored by specified key and increments it by value. If the key does not exist, it is created.
Errors: InvalidTypeError when the value stored at key is not integer.
func (*Store) Set ¶
Set sets the value of specified key.
Errors: InvalidKeyError when requested key could not be found.
func (*Store) SetLifetime ¶
SetLifetime modifies the lifetime for new stored items or for existing items when it is read or written.
Errors: NotSupportedError when ScopeNew is specified.
func (*Store) SetTransient ¶
SetTransient defines whether should extends expiration of stored value when it is read or written.