Documentation ¶
Overview ¶
Package mongostore provides MongoDB-backed data store implementation.
Store ¶
A Store provides MongoDB-backed key:value cache that expires after defined duration of time. That duration is defined when a new instance is initialized calling 'mongostore.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 existing values can be modified calling 'SetLifetime()'.
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 ¶
- Constants
- 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) EnsureAccuracy(value bool)
- 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 ¶
const ( // MongoDupKeyErrorCode defines MongoDB error code when trying to insert a // duplicated key. MongoDupKeyErrorCode = 11000 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
A Store provides a MongoDB-backed 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 MongoStore and defines the lifetime whether it is not already defined. The stored items lifetime are renewed when it is read or written.
func (*Store) Add ¶
Add adds a new key:value to current store.
Errors ¶
dot.DuplicatedKeyError when requested key already exists.
mgo.LastError when a error from MongoDB is triggered.
func (*Store) Count ¶
Count gets the number of stored values by current instance.
Errors: mgo.LastError when a error from MongoDB is triggered.
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 value.
Errors ¶
dot.InvalidKeyError when requested key already exists.
mgo.LastError when a error from MongoDB is triggered.
func (*Store) EnsureAccuracy ¶
EnsureAccuracy enables a double-check for expired values (slower). Because MongoDB does not garantee that expired data will be deleted immediately upon expiration.
func (*Store) Flush ¶
Flush deletes any cached value into current instance.
Errors: mgo.LastError when a error from MongoDB is triggered.
func (*Store) Get ¶
Get gets the value stored by specified key and stores the result in the value pointed to by ref.
Errors ¶
dot.InvalidKeyError when requested key already exists.
mgo.LastError when a error from MongoDB is triggered.
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 ¶
dot.InvalidKeyError when requested key already exists.
mgo.LastError when a error from MongoDB is triggered.
func (*Store) SetLifetime ¶
SetLifetime modifies the lifetime for new and existing stored items.
Errors: NotSupportedError when ScopeNewAndUpdate or ScopeNew is specified.
func (*Store) SetTransient ¶
SetTransient defines whether should extends expiration of stored value when it is read or written.