Documentation ¶
Overview ¶
Package data defines interfaces shared by other packages that implement data storages.
Store ¶
Store is the inteface implemented by an object that provides a storage for expirable values.
A Store object 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).
LifetimeScope ¶
A LifetimeScope which stored values will be affected by lifetime change.
Use 'ScopeAll' to apply the new lifetime for existing values and the ones that will be created on the future.
Use 'ScopeNewAndUpdated' to apply the new lifetime for existing values when they are read or written, and the ones that will be created on the future.
Use 'ScopeNew' to apply the new lifetime only for the ones that will be created on the future.
Index ¶
Constants ¶
const ( // ScopeAll defines that the new lifetime value should be applied for new // and existing store items. ScopeAll = LifetimeScope(0) // ScopeNewAndUpdated defines that new lifetime value should be applied for // new and future updates on stored items. // A stored item is updated when it is read or written. ScopeNewAndUpdated = LifetimeScope(1) // ScopeNew defines that new lifetime value should be applied for new store // items. ScopeNew = LifetimeScope(2) )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type InvalidTypeError ¶
type InvalidTypeError struct {
Value interface{}
}
A InvalidTypeError represents an error when value type is different than expected.
func NewInvalidTypeError ¶
func NewInvalidTypeError(value interface{}) InvalidTypeError
NewInvalidTypeError returns a new instance of InvalidTypeError.
func (InvalidTypeError) Error ¶
func (e InvalidTypeError) Error() string
Error returns string representation of current instance error.
type LifetimeScope ¶
type LifetimeScope int
A LifetimeScope its a value which defines scope to apply new lifetime value.
type Store ¶
type Store interface { // Add adds a new key:value to current store. // // Errors: // DuplicatedKeyError when requested key already exists. Add(key string, value interface{}) error // Count gets the number of stored values by current instance. // // Errors: // NotSupportedError when current method cannot be implemented. Count() (int, error) // Decrement atomically gets the value stored by specified key and // decrements it by one. If the key does not exist, it is created. Decrement(key string) (int, error) // DecrementBy atomically gets the value stored by specified key and // decrements it by value. If the key does not exist, it is created. DecrementBy(key string, value int) (int, error) // Delete deletes the specified value. // // Errors: // InvalidKeyError when requested key could not be found. Delete(key string) error // Flush deletes any cached value into current instance. // // Errors: // NotSupportedError when current method cannot be implemented. Flush() error // Get gets the value stored by specified key and stores the result in the // value pointed to by ref. // // Errors: // InvalidKeyError when requested key could not be found. Get(key string, ref interface{}) error // Increment atomically gets the value stored by specified key and // increments it by one. If the key does not exist, it is created. Increment(key string) (int, error) // IncrementBy atomically gets the value stored by specified key and // increments it by value. If the key does not exist, it is created. IncrementBy(key string, value int) (int, error) // Set sets the value of specified key. // // Errors: // InvalidKeyError when requested key could not be found. Set(key string, value interface{}) error // SetLifetime modifies the lifetime for a especified scope. // // Errors: // NotSupportedError when current method cannot be implemented. SetLifetime(time.Duration, LifetimeScope) error // SetTransient defines whether should extends expiration of stored value // when it is read or written. SetTransient(bool) }
A Store represents a data store whose its stored values expires after specific elapsed time since its creation or last access.
Directories ¶
Path | Synopsis |
---|---|
Package memstore provides in-memory data store implementation.
|
Package memstore provides in-memory data store implementation. |
Package mongostore provides MongoDB-backed data store implementation.
|
Package mongostore provides MongoDB-backed data store implementation. |