Documentation
¶
Overview ¶
Package mgokv defines cached MongoDB-backed global persistent storage for key-value pairs.
It is designed to be used when there is a small set of attributes that change infrequently. It shouldn't be used when there's an unbounded set of keys, as key entries are not deleted.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errgo.New("persistent data entry not found")
ErrNotFound is returned as the cause of the error when an entry is not found.
Functions ¶
This section is empty.
Types ¶
type Session ¶
type Session struct { *Store // contains filtered or unexported fields }
Session associates a Store instance with a mongo session.
func (*Session) Get ¶
Get gets the value associated with the given key into the value pointed to by v, which should be a pointer to the same struct type used to put the value originally.
If the value is not found, it returns ErrNotFound.
func (*Session) Put ¶
Put stores the given value for the given key. The value must be a struct type that is marshalable as BSON (see http://gopkg.in/mgo.v2/bson).
func (*Session) PutInitial ¶
PutInitial puts an initial value for the given key. It does nothing if there is already a value stored for the key. It reports whether the value was actually set.
func (*Session) Update ¶
Update updates the value using the MongoDB update operation specified in update. The value is stored in the "value" field in the document.
For example, if a value of type struct { N int } is associated with a key, then:
s.Update(key, bson.M{"$inc": bson.M{"value.n": 1}})
will atomically increment the N value.
If there is no value associated with the key, Update returns ErrNotFound.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store represents a cached set of key-value pairs.