mongostore

package
v0.0.0-...-c9ee01f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2016 License: Apache-2.0 Imports: 7 Imported by: 0

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

View Source
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

func New(db *mgo.Database, name string, d time.Duration) *Store

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

func (s *Store) Add(key string, value interface{}) error

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

func (s *Store) Count() (int, error)

Count gets the number of stored values by current instance.

Errors: mgo.LastError when a error from MongoDB is triggered.

func (*Store) Decrement

func (s *Store) Decrement(key string) (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.

Errors: InvalidTypeError when the value stored at key is not integer.

func (*Store) DecrementBy

func (s *Store) DecrementBy(key string, value int) (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.

Errors: InvalidTypeError when the value stored at key is not integer.

func (*Store) Delete

func (s *Store) Delete(key string) error

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

func (s *Store) EnsureAccuracy(value bool)

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

func (s *Store) Flush() error

Flush deletes any cached value into current instance.

Errors: mgo.LastError when a error from MongoDB is triggered.

func (*Store) Get

func (s *Store) Get(key string, ref interface{}) error

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

func (s *Store) Increment(key string) (int, error)

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

func (s *Store) IncrementBy(key string, value int) (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.

Errors: InvalidTypeError when the value stored at key is not integer.

func (*Store) Set

func (s *Store) Set(key string, value interface{}) error

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

func (s *Store) SetLifetime(d time.Duration, scope data.LifetimeScope) error

SetLifetime modifies the lifetime for new and existing stored items.

Errors: NotSupportedError when ScopeNewAndUpdate or ScopeNew is specified.

func (*Store) SetTransient

func (s *Store) SetTransient(value bool)

SetTransient defines whether should extends expiration of stored value when it is read or written.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL