meercache
v0.0.2
Published
a lightweight caching layer for Meerkat and downstream modules such as Timon
Downloads
3
Maintainers
Readme
Meercache
A lightweight caching layer for Meerkat and downstream modules such as Timon
Getting Started
Install Meercache:
npm install meercache --save
Examples
Meercache was written to facilitate judicious caching of MongoDB documents retrieved via Meerkat and downstream modules such as Timon. Meercache should only be leveraged in specific use cases. Particularly where collections are both bounded, and are rarely updated or removed. Even collections limited to thousands of documents may be too large. Meercache is a local, in-memory cache which can have a dramatic positive effect on performance and scale. However, immediate invalidation can be tricky and tedious across clusters.
Declare a Meercached Timon Model (models/account.coffee)
{ extend, pick } = require 'lodash'
keygen = require 'keygen'
cache = require('meercache') [ 'id' ], [ 'identifier' ], [ 'email' ], 300
Account = require('timon').extend module, 'account',
for_id: (id, failure, success) ->
cache.proxy(@, @find_one, 'id') { id }, failure, success
for_identifier: (identifier, failure, success) ->
cache.proxy(@, @find_one, 'identifier') { identifier }, failure, success
for_creds: (identifier, secret, failure, success) ->
[ success, failure ] = [ failure, success ] unless success?
@for_identifier identifier, failure, (account) ->
success if account?.secret is secret then account else null
for_email: (email, failure, success) ->
cache.proxy(@, @find_one, 'email') { email }, failure, success
remove: (account, failure, success) ->
cache.invalidate(@, @super.remove, 'id') id: @id_for account, failure
Account.default 'insert', ->
identifier: keygen.url keygen.small
secret: keygen.url keygen.large
extend Account,
cache: pick cache, 'flush', 'stats'
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.
Release History
(Nothing yet)