node-shared-cache
Advanced tools
Comparing version 1.6.0 to 1.6.2
{ | ||
"name": "node-shared-cache", | ||
"version": "1.6.0", | ||
"version": "1.6.2", | ||
"description": "Interprocess shared memory cache for Node.JS", | ||
"main": "index.js", | ||
"dependencies": { | ||
"nan": "~2.2.0" | ||
"nan": "~2.4.0" | ||
}, | ||
"devDependencies": {}, | ||
"scripts": { | ||
"test": "node test", | ||
"test": "node test/test", | ||
"install": "node-gyp rebuild" | ||
@@ -13,0 +13,0 @@ }, |
@@ -9,15 +9,19 @@ ## node-shared-cache | ||
- 1.5.0 Add support for Win32 ([#7](https://github.com/kyriosli/node-shared-cache/issues/7)). Thanks to [@matthias-christen](https://github.com/matthias-christen) [@dancrumb](https://github.com/dancrumb) | ||
- 1.6.2 | ||
- Add `exchange` method which can be used as atomic lock as well as `increase` | ||
- Add `fastGet` method which does not touch the LRU sequence | ||
- 1.6.1 Update `nan` requirement to 2.4.0 | ||
- 1.6.0 Add support for Win32 ([#7](https://github.com/kyriosli/node-shared-cache/issues/7)). Thanks to [@matthias-christen](https://github.com/matthias-christen) [@dancrumb](https://github.com/dancrumb) | ||
## Install | ||
Install `node-gyp` first if you do not have it installed: | ||
You can install it with npm. Just type `npm i node-shared-cache` will do it. | ||
sudo npm install node-gyp -g | ||
You can also download and install it manually, but you need to install Node.JS and `node-gyp` first. | ||
Then | ||
git clone https://github.com/kyriosli/node-shared-cache.git | ||
cd node-shared-cache | ||
node-gyp rebuild | ||
npm install kyriosli/node-shared-cache | ||
## Terms of Use | ||
@@ -52,13 +56,19 @@ | ||
```js | ||
// create cache instance | ||
var cache = require('node-shared-cache'); | ||
var obj = new cache.Cache("test", 557056); | ||
// setting property | ||
obj.foo = "bar"; | ||
// getting property | ||
console.log(obj.foo); | ||
// enumerating properties | ||
for(var k in obj); | ||
Object.keys(obj); | ||
// deleting property | ||
delete obj.foo; | ||
// writing objects is also supported | ||
@@ -69,2 +79,3 @@ obj.foo = {'foo': 'bar'}; | ||
test === obj.foo; // false | ||
// circular reference is supported. | ||
@@ -76,7 +87,15 @@ test.self = test; | ||
test.self === test; // true | ||
// release memory region | ||
cache.release("test"); | ||
// increase a key | ||
cache.increase(obj, "foo"); | ||
cache.increase(obj, "foo", 3); | ||
// exchange current key with new value, the old value is returned | ||
cache.set(obj, "foo", 123); | ||
cache.exchange(obj, "foo", 456); // 123 | ||
obj.foo; // 456 | ||
// release memory region | ||
cache.release("test"); | ||
// dump current cache | ||
@@ -86,3 +105,2 @@ var values = cache.dump(obj); | ||
values = cache.dump(obj, "foo_"); | ||
``` | ||
@@ -94,3 +112,5 @@ | ||
```js | ||
function Cache(name, size, optional block_size) | ||
``` | ||
@@ -121,3 +141,5 @@ `name` represents a file name in shared memory, `size` represents memory size in bytes to be used. `block_size` denotes the size of the unit of the memory block. | ||
set(name, value) | ||
```js | ||
set(name, value) | ||
``` | ||
@@ -128,3 +150,5 @@ ### exported methods | ||
function release(name) | ||
```js | ||
function release(name) | ||
``` | ||
@@ -143,9 +167,30 @@ The shared memory named `name` will be released. Throws error if shared memory is not found. Note that this method simply calls `shm_unlink` and does not check whether the memory region is really initiated by this module. | ||
function increase(instance, name, optional increase_by) | ||
```js | ||
function increase(instance, name, optional increase_by) | ||
``` | ||
Increase a key in the cache by an integer (default to 1). If the key is absent, or not an integer, the key will be set to `increase_by`. | ||
#### exchange | ||
```js | ||
function exchange(instance, name, new_value) | ||
``` | ||
Update a key in the cache with a new value, the old value is returned. | ||
#### fastGet | ||
```js | ||
function fastGet(instance, name) | ||
``` | ||
Get the value of a key without touching the LRU sequence. This method is usually faster than `instance[name]` because it uses | ||
different lock mechanism to ensure shared reading across processes. | ||
#### dump | ||
```js | ||
function dump(instance, optional prefix) | ||
``` | ||
@@ -157,17 +202,18 @@ Dump keys and values | ||
Tests are run under a virtual machine with one processor: | ||
```sh | ||
$ node -v | ||
v0.12.4 | ||
$ cat /proc/cpuinfo | ||
processor : 0 | ||
vendor_id : GenuineIntel | ||
cpu family : 6 | ||
model : 45 | ||
model name : Intel(R) Xeon(R) CPU E5-2630 0 @ 2.30GHz | ||
stepping : 7 | ||
microcode : 0x70d | ||
cpu MHz : 2300.090 | ||
cache size : 15360 KB | ||
... | ||
``` | ||
$ node -v | ||
v0.12.4 | ||
$ cat /proc/cpuinfo | ||
processor : 0 | ||
vendor_id : GenuineIntel | ||
cpu family : 6 | ||
model : 45 | ||
model name : Intel(R) Xeon(R) CPU E5-2630 0 @ 2.30GHz | ||
stepping : 7 | ||
microcode : 0x70d | ||
cpu MHz : 2300.090 | ||
cache size : 15360 KB | ||
... | ||
Block size is set to 64 and 1MB of memory is used. | ||
@@ -174,0 +220,0 @@ |
@@ -45,2 +45,8 @@ var binding = require('../index.js'); | ||
for(var i = 0; i < 1e6; i++) { | ||
binding.fastGet(obj, 'test' + (i & 127)); | ||
} | ||
console.log('fastGet 100w times: %sms', end()); | ||
begin(); | ||
for(var i = 0; i < 1e6; i++) { | ||
plain['oops' + (i & 127)]; | ||
@@ -47,0 +53,0 @@ } |
@@ -57,2 +57,10 @@ var assert = require('assert'); | ||
// test exchange | ||
assert.strictEqual(binding.exchange(obj, 'foo2', 5678), 1234); | ||
assert.strictEqual(obj.foo2, 5678); | ||
assert.strictEqual(binding.exchange(obj, 'blah', 'mew'), undefined); | ||
assert.strictEqual(obj.blah, 'mew'); | ||
assert.strictEqual(binding.fastGet(obj, 'blah'), 'mew'); | ||
assert.strictEqual(binding.fastGet(obj, 'blah~'), undefined); | ||
delete obj.foo; | ||
@@ -59,0 +67,0 @@ assert.ifError('foo' in obj); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
86307
25
317
359
+ Addednan@2.4.0(transitive)
- Removednan@2.2.1(transitive)
Updatednan@~2.4.0