cache-service
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -55,3 +55,3 @@ var cacheModule = require('./cacheModule'); | ||
this.cache.delete = function(keys, cb){ | ||
this.cache.del = function(keys, cb){ | ||
try { | ||
@@ -58,0 +58,0 @@ this.db.del(keys, function (err, count){ |
@@ -71,3 +71,3 @@ var cacheModule = require('./cacheModule'); | ||
this.cache.delete = function(keys, cb){ | ||
this.cache.del = function(keys, cb){ | ||
try { | ||
@@ -74,0 +74,0 @@ this.db.del(keys, function (err, count){ |
@@ -14,4 +14,4 @@ var cacheCollection = require('./cacheCollection'); | ||
self.getKey = function(key, cb){ | ||
self.log(false, 'getKey() called for key:', {key: key}); | ||
self.get = function(key, cb){ | ||
self.log(false, 'get() called for key:', {key: key}); | ||
var curCache; | ||
@@ -41,3 +41,3 @@ var curCacheIndex = 0; | ||
else { | ||
self.log(false, 'getKey() key not found:', {key: key}); | ||
self.log(false, 'get() key not found:', {key: key}); | ||
cb(null, null); | ||
@@ -49,3 +49,3 @@ } | ||
self.setKey = function(key, value, expiration, cb){ | ||
self.set = function(key, value, expiration, cb){ | ||
for(var i = 0; i < self.cacheCollection.preApi.length; i++){ | ||
@@ -72,10 +72,10 @@ cache = self.cacheCollection.preApi[i]; | ||
self.deleteKeys = function(keys, cb){ | ||
self.del = function(keys, cb){ | ||
for(var i = 0; i < self.cacheCollection.preApi.length; i++){ | ||
cache = self.cacheCollection.preApi[i]; | ||
if(i === 0){ | ||
cache.delete(keys, cb); | ||
cache.del(keys, cb); | ||
} | ||
else{ | ||
cache.delete(keys); | ||
cache.del(keys); | ||
} | ||
@@ -86,6 +86,6 @@ } | ||
if(i === 0){ | ||
cache.delete(keys, cb); | ||
cache.del(keys, cb); | ||
} | ||
else{ | ||
cache.delete(keys); | ||
cache.del(keys); | ||
} | ||
@@ -96,3 +96,3 @@ } | ||
self.flushKeys = function(){ | ||
self.flush = function(){ | ||
for(var i = 0; i < self.cacheCollection.preApi.length; i++){ | ||
@@ -99,0 +99,0 @@ cache = self.cacheCollection.preApi[i]; |
{ | ||
"name": "cache-service", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "A tiered caching solution for node.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -7,7 +7,7 @@ # cache-service | ||
## What Does cache-service Do? | ||
# What Does cache-service Do? | ||
cache-service allows you to create redundant, cache-agnostic caching configurations. By default, it supports redis and node-cach, but you can add any cache you want as long as you follow the same interface. | ||
## Basic Usage | ||
# Basic Usage | ||
@@ -40,3 +40,3 @@ Require and instantiate cache-service as follows: | ||
## Install | ||
# Install | ||
@@ -47,3 +47,3 @@ ```javascript | ||
## Run Tests | ||
# Run Tests | ||
@@ -54,3 +54,3 @@ ```javascript | ||
## What Does the Default Configuration Give Me? | ||
# What Does the Default Configuration Give Me? | ||
@@ -64,3 +64,3 @@ By following the [Basic Usage](basic-usage) example above, cache-service will: | ||
## Constructor | ||
# Constructor | ||
@@ -73,7 +73,7 @@ cache-service's constructor takes two optional parameters in the following order: [cacheServiceConfig](cache-service-configuraiton-object) and [cacheModuleConfig](cache-module-configuration-object): | ||
## Cache Service Configuration Object | ||
# Cache Service Configuration Object | ||
This is where you set cache-service-level config options. | ||
#### nameSpace | ||
## nameSpace | ||
@@ -85,3 +85,3 @@ A namespace to be applied to all keys generated for this instance of cache-service. | ||
#### verbose | ||
## verbose | ||
@@ -93,5 +93,5 @@ When false, cache-service will log only errors. When true, cache-service will log all activity (useful for testing and debugging). | ||
#### writeToVolatileCaches | ||
## writeToVolatileCaches | ||
Let's say you have an instance of cache-service with two caches inside of it: cacheA and cacheB. If cacheA has a shorter [defaultExpiration](defaultExpiration) than cacheB and cacheA does not have the key for which you're looking, cache-service will then look in cacheB. If cache-service finds the desired key in cacheB and `writeToVolatileCaches` is `true`, cache-service will then write that key to cacheA. | ||
Let's say you have an instance of cache-service with two caches inside of it: cacheA and cacheB. If cacheA has a shorter [defaultExpiration](#defaultexpiration) than cacheB and cacheA does not have the key for which you're looking, cache-service will then look in cacheB. If cache-service finds the desired key in cacheB and `writeToVolatileCaches` is `true`, cache-service will then write that key to cacheA. | ||
@@ -103,3 +103,3 @@ This is particularly useful if you want to have a short-term in-memory cache with the most used queries and a longer-term redis cache with all of the cached data. | ||
## Cache Module Configuration Object | ||
# Cache Module Configuration Object | ||
@@ -127,3 +127,3 @@ This is where you tell cache-service which caches you want and how you want them configured. Here is an example cacheModuleConfig: | ||
###### type | ||
## type | ||
@@ -136,3 +136,3 @@ This is the type of cache you want to use. Currently, the only options are 'redis', 'node-cache', and 'custom'. If you choose 'redis' or 'node-cache', cache-service will create an instance of that cache type for you using the assiciated config options. If you choose 'custom', you can pass in your own cache instance and it will work as long as you match the [Cache Module Interface](#cache-module-interface). | ||
#### defaultExpiration | ||
## defaultExpiration | ||
@@ -145,3 +145,3 @@ The expiration to include when executing cache set commands. Can be overridden via `.setKey()`'s optional expiraiton param. | ||
#### checkOnPreviousEmpty | ||
## checkOnPreviousEmpty | ||
@@ -153,6 +153,11 @@ By default, if two subsequent caches have the same `defaultExpiraiton`, the second of the two caches will not be checked in the event that the first cache does not have a key. If `checkOnPreviousEmpty` is `true`, cache-service will check subsequent caches with the same `defaultExpiration`. | ||
#### readOnly | ||
## readOnly | ||
#### postApi (Currently not implemented) | ||
Whether a cache should not be written to. Useful if you're sharing a redis cache with another team and your contract with them is that you will not alter their data. | ||
* type: boolean | ||
* default: false | ||
## postApi (Currently not implemented) | ||
Only for use with [superagent-cache](https://github.com/jpodwys/superagent-cache). Whether this cache should be evaluated only in the event of an API failure. This is useful when you want to have an extremely long-term cache to serve data when an API is down. Currently, only the first cache module with postApi set to true will be used. | ||
@@ -163,6 +168,6 @@ | ||
## API | ||
# API | ||
##More Documentation Coming Soon | ||
# More Documentation Coming Soon |
@@ -19,9 +19,9 @@ var expect = require('expect'); | ||
beforeEach(function(){ | ||
cacheService.flushKeys(); | ||
cacheService.flush(); | ||
}); | ||
describe('cachService API tests', function () { | ||
it('.setKey(k, v), .getKey(k)', function (done) { | ||
cacheService.setKey(key, value); | ||
cacheService.getKey(key, function (err, response){ | ||
it('.set(k, v), .get(k)', function (done) { | ||
cacheService.set(key, value); | ||
cacheService.get(key, function (err, response){ | ||
expect(response).toBe('value'); | ||
@@ -31,6 +31,6 @@ done(); | ||
}); | ||
it('.setKey(k, v, exp), .getKey(k)', function (done) { | ||
cacheService.setKey(key, value, 0.001); | ||
it('.set(k, v, exp), .get(k)', function (done) { | ||
cacheService.set(key, value, 0.001); | ||
setTimeout(function(){ | ||
cacheService.getKey(key, function (err, response){ | ||
cacheService.get(key, function (err, response){ | ||
expect(response).toBe(null); | ||
@@ -41,7 +41,7 @@ done(); | ||
}); | ||
it('.deleteKeys(string)', function (done) { | ||
cacheService.setKey(key, value); | ||
cacheService.deleteKeys(key, function (err, count){ | ||
it('.del(string)', function (done) { | ||
cacheService.set(key, value); | ||
cacheService.del(key, function (err, count){ | ||
expect(count).toBe(1); | ||
cacheService.getKey(key, function (err, response){ | ||
cacheService.get(key, function (err, response){ | ||
expect(response).toBe(null); | ||
@@ -52,10 +52,10 @@ done(); | ||
}); | ||
it('.deleteKeys(array)', function (done) { | ||
cacheService.setKey(key, value); | ||
cacheService.setKey('key2', 'value2'); | ||
cacheService.deleteKeys([key, 'key2'], function (err, count){ | ||
it('.del(array)', function (done) { | ||
cacheService.set(key, value); | ||
cacheService.set('key2', 'value2'); | ||
cacheService.del([key, 'key2'], function (err, count){ | ||
expect(count).toBe(2); | ||
cacheService.getKey(key, function (err, response){ | ||
cacheService.get(key, function (err, response){ | ||
expect(response).toBe(null); | ||
cacheService.getKey('key2', function (err, response){ | ||
cacheService.get('key2', function (err, response){ | ||
expect(response).toBe(null); | ||
@@ -70,4 +70,4 @@ done(); | ||
describe('cachService caching tests', function () { | ||
it('.setKey() should add data to all caches', function (done) { | ||
cacheService.setKey(key, value); | ||
it('.set() should add data to all caches', function (done) { | ||
cacheService.set(key, value); | ||
var caches = cacheService.cacheCollection.preApi; | ||
@@ -82,10 +82,10 @@ for(var i = 0; i < caches.length; i++){ | ||
}); | ||
it('.getKey(k) should search subsequent caches with longer default expirations when k is not found in earlier caches', function (done) { | ||
cacheService.setKey(key, value); | ||
it('.get(k) should search subsequent caches with longer default expirations when k is not found in earlier caches', function (done) { | ||
cacheService.set(key, value); | ||
var firstCache = cacheService.cacheCollection.preApi[0]; | ||
firstCache.delete(key, function (err, count){ | ||
firstCache.del(key, function (err, count){ | ||
expect(count).toBe(1); | ||
firstCache.get(key, function (err, response){ | ||
expect(response).toBe(null); | ||
cacheService.getKey(key, function (err, response){ | ||
cacheService.get(key, function (err, response){ | ||
expect(response).toBe(value); | ||
@@ -92,0 +92,0 @@ done(); |
@@ -29,3 +29,3 @@ var expect = require('expect'); | ||
nodeCache.set(key, value); | ||
nodeCache.delete(key); | ||
nodeCache.del(key); | ||
nodeCache.get(key, function (err, result) { | ||
@@ -32,0 +32,0 @@ expect(result).toBe(null); |
@@ -31,3 +31,3 @@ var expect = require('expect'); | ||
redisCache.set(key, value); | ||
redisCache.delete(key); | ||
redisCache.del(key); | ||
redisCache.get(key, function (err, result) { | ||
@@ -34,0 +34,0 @@ expect(result).toBe(null); |
26272
160