An extensible node.js URL caching library
redis-url-cache helps you store and retrieve url content from a Redis datastore.
npm install redis-url-cache
Create your config files with the following content
//cache.config.js
module.exports.rules = {
always: [],
maxAge: [],
never: []
default: 'always'
};
module.exports.redis = {
host: 127.0.0.1,
port: 6379
}
This will store indefinitively all urls by default
This will store this instance definition inside Redis. This should be executed only once.
const CacheCreator = require('redis-url-cache').RedisUrlCache.CacheCreator;
const {redis, rules} = require('cache-config');
CacheCreator.createCache('INSTANCE_1', false, redis, rules, err => { });
const {Instance, CacheEngineCB, CacheEnginePromise} = require('redis-url-cache').RedisUrlCache;
const {redis} = require('cache-config');
const instance = new Instance('INSTANCE_1', redis, {}, (err) => {} );
const cacheEngineCB = new CacheEngineCB('http://www.yoursite.com', instance);
//or use the promise support instead
const cacheEnginePromise = new CacheEnginePromise('http://www.yoursite.com', instance);
const urlCB = cacheEngineCB.url('/someRelative.html');
const urlPromise = cacheEnginePromise.url('/someRelative.html');
urlCB.set('Hello', { headers: [] }, false, (err, status) => {
if(err) throw err;
} );
urlCB.get( (err, result) => {
//result = {
content: 'Hello',
extra: { headers: [] },
createdOn: 12345677
}
} );
urlPromise.has().then( exists => {
//exists = true because these two cacheEngines share the same instance and same default domain.
}, err => {});
Check out the API to learn more.