Skip to content

Commit e73a2ba

Browse files
Merge pull request #5 from PLG-Works/redis_version_update
## Cache v1.0.2 - `redis` NPM version updated to 3.1.1 for fixing `Potential exponential regex in monitor mode` security vulnerability.
2 parents 1bf5220 + 39b6447 commit e73a2ba

4 files changed

Lines changed: 48 additions & 55 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33

44
## Cache v1.0.1
55
- First time cache set intermittent issue fixed for memcached.
6+
7+
## Cache v1.0.2
8+
- `redis` NPM version updated to 3.1.1 for fixing `Potential exponential regex in monitor mode` security vulnerability.

README.md

Lines changed: 42 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
#Cache
1+
# Cache
22

33
[![Latest version](https://img.shields.io/npm/v/@plgworks/cache.svg?maxAge=3600)][npm]
4-
[![Downloads per month](https://img.shields.io/npm/dm/@plgworks/cache.svg?maxAge=3600)][npm]
54

65
[npm]: https://www.npmjs.com/package/@plgworks/cache
76

8-
Cache is the central cache implementation module for several modules.
9-
It contains three caching engines. The decision of which caching engine to use is governed while creating the cache object.
10-
The caching engines implemented are:
11-
12-
* [Memcached](https://memcached.org/)
13-
* [Redis](https://redis.io/docs/)
14-
* In-memory (use with single threaded process in development mode only)
7+
Cache NPM implements wrapper over multiple caching engines - [Memcached](https://memcached.org/), [Redis](https://redis.io/docs/) and In-memory (use with single threaded process in development mode only).
8+
The decision of which caching engine to use is governed while creating the Cache NPM object.
159

1610
## Why Cache?
1711
Core packages of different caching systems do not have a common interface, i.e. they have the same functionality implemented with different method signatures.
@@ -29,11 +23,23 @@ npm install @plgworks/cache --save
2923

3024
## Initialize
3125

32-
### Cache Initialization Params
26+
```js
27+
const Cache = require('@plgworks/cache');
28+
29+
const configStrategy = {}; // Refer the next section for detailed documentation on configStrategy
30+
const cache = Cache.getInstance(configStrategy);
31+
32+
const cacheImplementer = cache.cacheInstance;
33+
```
34+
35+
**Note**: To print detailed logs, add `CACHE_DEBUG_ENABLED = '1'` in your env variables.
36+
37+
### Config Strategy
3338
**`configStrategy`** is a mandatory parameter which specifies the configuration strategy to be used for a particular cache engine.
34-
An example of the configStrategy is:
39+
40+
An example of the configStrategy is:
3541
```js
36-
configStrategy = {
42+
const configStrategy = {
3743
cache: {
3844
engine: "none/redis/memcached",
3945
host: "",
@@ -58,11 +64,10 @@ configStrategy = {
5864
- **namespace**: It is in-memory cache namespace.
5965

6066

61-
<b>Below are the examples of configStrategies:</b>
62-
* Redis
63-
67+
#### Redis Example
68+
Following is an example of redis engine config strategy to be used in initializing Cache.
6469
```js
65-
configStrategy = {
70+
const configStrategy = {
6671
cache: {
6772
engine: "redis",
6873
host: "localhost",
@@ -74,10 +79,10 @@ configStrategy = {
7479
}
7580
}
7681
````
77-
* Memcached
78-
82+
#### Memcache Example
83+
Following is an example of memcache engine config strategy to be used in initializing Cache.
7984
```js
80-
configStrategy = {
85+
const configStrategy = {
8186
cache: {
8287
engine: "memcached",
8388
servers: ["127.0.0.1:11211"],
@@ -86,9 +91,10 @@ configStrategy = {
8691
}
8792
}
8893
````
89-
* In-memory
94+
#### In-memory Example
95+
Following is an example of in-memory engine config strategy to be used in initializing Cache.
9096
```js
91-
configStrategy = {
97+
const configStrategy = {
9298
cache: {
9399
engine: "none",
94100
namespace: "A",
@@ -98,20 +104,10 @@ configStrategy = {
98104
}
99105
```
100106

101-
### Create Cache Object:
102-
103-
```js
104-
Cache = require('@plgworks/cache');
105-
cache = Cache.getInstance(configStrategy);
106-
107-
cacheImplementer = cache.cacheInstance;
108-
```
109-
Note: To print detailed logs, add `CACHE_DEBUG_ENABLED = '1'` in your env variables.
110-
111-
## Examples:
107+
## `cacheImplementer` methods
108+
Irrespective of the caching engine, the methods exposed in `cacheImplementer` have the consistent signature.
112109

113110
### Store and retrieve data in cache using `set` and `get`:
114-
115111
```js
116112
const resolvePromise = function(cacheResponse){
117113
if (cacheResponse.isSuccess()) {
@@ -162,41 +158,35 @@ cacheImplementer.decrement('testCounterKey', 5).then(resolvePromise);
162158

163159
```js
164160
cacheImplementer.set('testKey', "testData").then(console.log);
165-
cacheImplementer.touch('testKey', 10).then(function(cacheResponse){
166-
if (cacheResponse.isSuccess()) {
167-
console.log(cacheResponse.data.response);
168-
} else {
169-
console.log(cacheResponse);
170-
}
171-
});
161+
cacheImplementer.touch('testKey', 10).then(resolvePromise);
172162
```
173163

174164
## Running test cases
175165
### Set environment variables of particular cache engine for which you want to run the tests.
176166

177167
* Redis
178-
````
168+
```shell script
179169
source test/env/redis.sh
180-
````
170+
```
181171
* Memcached
182-
````
172+
```shell script
183173
source test/env/memcached.sh
184-
````
174+
```
185175
* In-memory
186-
````
176+
```shell script
187177
source test/env/inMemory.sh
188-
````
178+
```
189179
### Cache engines must be running on the specified ports.
190180

191181
* Redis (6380,6381)
192-
````
182+
```shell script
193183
redis-server --port 6380
194-
````
184+
```
195185
* Memcached (11212,11213,11214,11215)
196-
````
186+
```shell script
197187
memcached -p 11212 -d
198-
````
188+
```
199189
### Run tests
200-
````
190+
```shell script
201191
./node_modules/.bin/mocha --recursive "./test/*.js"
202-
````
192+
```

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.1
1+
1.0.2

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@plgworks/cache",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "Cache is the central cache implementation for several modules.",
55
"main": "index.js",
66
"scripts": {
@@ -26,7 +26,7 @@
2626
"homepage": "https://github.com/PLG-Works/cache#readme",
2727
"dependencies": {
2828
"memcached": "2.2.2",
29-
"redis": "3.0.2",
29+
"redis": "3.1.1",
3030
"@plgworks/base": "^1.0.0"
3131
},
3232
"devDependencies": {

0 commit comments

Comments
 (0)