Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cache-manager

Package Overview
Dependencies
Maintainers
1
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache-manager - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

6

lib/caching.js

@@ -5,3 +5,7 @@ var caching = function (args) {

if (typeof args.store === 'object') {
self.store = args.store;
if (args.store.create) {
self.store = args.store.create(args);
} else {
self.store = args.store;
}
} else if (typeof args.store === 'string' && args.store.match(/\//)) {

@@ -8,0 +12,0 @@ self.store = require(args.store).create(args);

8

lib/multi_caching.js
var async = require('async');
/**
* Module that lets you specify a hiearchy of caches.
* Module that lets you specify a hierarchy of caches.
*/

@@ -46,5 +46,5 @@ var multi_caching = function (caches) {

if (result) {
var caches_to_set = caches.slice(0, index);
set_in_multiple_caches(caches_to_set, key, result, function (err) {
return cb(err, result);
var caches_to_update = caches.slice(0, index);
set_in_multiple_caches(caches_to_update, key, result, function (err) {
cb(err, result);
});

@@ -51,0 +51,0 @@ } else {

@@ -0,1 +1,6 @@

/**
* Note: You very likely want to use your own Redis-based cache store instead
* of this one, especially for connection pooling. This is primarily an
* example implementation.
*/
function redis_store(args) {

@@ -2,0 +7,0 @@ args = args || {};

{
"name": "cache-manager",
"version": "0.0.1",
"version": "0.0.2",
"description": "Cache module for Node.js",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -92,4 +92,20 @@ node-cache-manager

// { id: 123, name: 'Bob' }
```
#### Custom Stores
You can use your own custom store by creating one with the same API as the
build-in redis and memory stores. To use your own store, you can either pass
in an instance of it, or pass in the path to the module.
E.g.,
```javascript
var my_store = require('your-homemade-store');
var cache = cache_manager.caching({store: my_store});
// or
var cache = cache_manager.caching({store: '/path/to/your/store'});
```
### Multi-Store

@@ -96,0 +112,0 @@

@@ -351,3 +351,15 @@ var assert = require('assert');

});
it("allows us to pass in a module (uninstantiated)", function (done) {
var store = memory_store;
cache = caching({store: store});
cache.set(key, value, function (err) {
check_err(err);
cache.get(key, function (err, result) {
assert.equal(result, value);
done();
});
});
});
});
});

@@ -64,2 +64,25 @@ var assert = require('assert');

});
it("lets us set data without a callback", function (done) {
multi_cache.set(key, value);
setTimeout(function () {
multi_cache.get(key, function (err, result) {
assert.equal(result, value);
memory_cache.get(key, function (err, result) {
assert.equal(result, value);
redis_cache.get(key, function (err, result) {
check_err(err);
assert.equal(result, value);
memory_cache2.get(key, function (err, result) {
check_err(err);
assert.equal(result, value);
done();
});
});
});
});
}, 20);
});
});

@@ -106,2 +129,27 @@

});
it("lets us delete data without a callback", function (done) {
multi_cache.set(key, value, function (err) {
check_err(err);
multi_cache.del(key);
setTimeout(function () {
memory_cache.get(key, function (err, result) {
assert.ok(!result);
redis_cache.get(key, function (err, result) {
check_err(err);
assert.ok(!result);
memory_cache2.get(key, function (err, result) {
check_err(err);
assert.ok(!result);
done();
});
});
});
});
}, 10);
});
});

@@ -379,3 +427,3 @@ });

context("when instantiated non-Array 'caches' arg", function () {
context("when instantiated with a non-Array 'caches' arg", function () {
it("throws an error", function () {

@@ -382,0 +430,0 @@ assert.throws(function () {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc