Interception module for caching the results returned by the intercepted methods.
IMPORTANT: this interceptor breaks the call chain and returns immediately if the requested item is cached, therefore subsequent interceptors and the method itself will not be invoked.
The interceptor uses node-cache-manager library for caching. Please refer to node-cache-manager documentation for more details on configuration and usage.
For more details on using interceptors please see the Interceptors tutorial.
- Source:
Example
var entree = require("entree"), cache = entree.resolveInterceptor("cache"), stores = [ { store: "memory", max: 1000, ttl: 10 }, { store: require("./redis_store"), db: 0, ttl: 100 } ]; entree.posts.use(cache.interception(stores, ["get"]));
Methods
-
<static> interception(stores, actions) → {function}
-
Configures and returns an interceptor function.
Parameters:
Name Type Argument Description stores
object <optional>
defines the cache stores. By default only memory store is used with the following configuration:
{ store: "memory", max: 1000, ttl: 10 }
.actions
string | Array.<string> <optional>
Specifies which actions (methods) should be cached. Could be single action or an array of actions. If omitted, all actions are cached. Possible values are:
["insert", "upsert", "update", "get", "delete", "select"]
- Source:
Returns:
- Type
- function