clydeio-memory-cache
v0.1.3
Published
Memory cache filter for Clyde API gateway.
Downloads
5
Readme
Memory Cache Filter
Memory cache filter implementation for Clyde API gateway.
Implementation is based on node-cache module.
The filter works as an in memory <key, value>
cache. For each request it caches response content, headers and status code as the value and using the url
as the key.
If the property ignoreQuery=true
the key will contain only the path
part of the url
and will ignore the query
, for example, these URLs will be treated as the same: /some_path?param1=a¶m2=b
, /some_path?abc
or /some_path
.
Installation
npm install clydeio-memory-cache --save
Configuration
The memory cache filter accepts the next set of configuration options. Note, with the exception of ignoreQuery
property all the rest properties are the same as the node-cache module, because of this, the set of properties are passed directly to the internal module reference:
ignoreQuery
: (default:false
) ignores the query part of theurl
when computing the cachekey
. Otherwise the fullurl
is used.stdTTL
: (default:0
) the standard ttl as number in seconds for every generated cache element.0
= unlimitedcheckperiod
: (default:600
) The period in seconds, as a number, used for the automatic delete check interval.0
= no periodic check.
Note: If you usecheckperiod > 0
you script will not exit at the end, because a internal timeout will always be active.useClones
: (default:true
) en/disable cloning of variables. Iftrue
you'll get a copy of the cached variable. Iffalse
you'll save and get just the reference.
Note:true
is recommended, because it'll behave like a sever-based caching. You should setfalse
if you want to save complex varibale types like functions, promises, regexp, ...
Examples
Global cache with default configuration
{
"prefilters" : [
{
"id" : "memory-cache",
"path" : "clydeio-memory-cache"
}
],
"providers": [
...
]
}
Provider's cache ignoring URL query part and with a TTL of 5 minutes
{
"providers": [
{
"id" : "providerA",
"context" : "/provider",
"target" : "http://server_providerA",
"prefilters" : [
{
"id" : "memory-cache",
"path" : "clydeio-memory-cache",
"config" : {
"ignoreQuery" : true,
"stdTTL" : 300
}
}
]
}
]
}
Notes
- Memory cache filter must be configured as a prefilter. Its is required to capture the requests before sent to the provider.
License
The MIT License (MIT)
Copyright (c) 2015 Antonio Santiago (@acanimal)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.