Use MongoDB as a key/value store. This is useful only for those who already use MongoDB and don't want to add another layer to their stack or need to cache MongoDB-specific things like ObjectIDs.
Documents are stored as:
{
"_id": "<key>",
"value": "<value>",
"expires": "<Date>",
"created": "<Date>"
}
Create a new mash
instance.
Options are:
collection
- the MongoDB collection to usemaxAge
- default expiration age
Set the default max age.
Set the MongoDB collection to use. Does not support capped collections.
Set the value. Can optionally override the default maxAge
.
Optionally you can chain:
.new()
- return the doc.w('majority')
- a write concern
Retrieve the cached value if one exists.
Optionally set a maxAge
that overrides the one set by .set().
Optionally you can chain:
.readPreference('nearest')
- read preference
Evict all documents based on a key
,
which could also be a MongoDB expression.
Optionally you can chain:
.w('majority')
- a write concern
Ensure the index on the curret collection. Converts it into a TTL collection.