Skip to content

Commit 0d8ef7d

Browse files
readme changes.
1 parent 8b560b5 commit 0d8ef7d

1 file changed

Lines changed: 25 additions & 34 deletions

File tree

README.md

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,8 @@
55

66
[npm]: https://www.npmjs.com/package/@plgworks/cache
77

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)
8+
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).
9+
The decision of which caching engine to use is governed while creating the Cache NPM object.
1510

1611
## Why Cache?
1712
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,9 +24,21 @@ npm install @plgworks/cache --save
2924

3025
## Initialize
3126

32-
### Cache Initialization Params
27+
```js
28+
const Cache = require('@plgworks/cache');
29+
30+
const configStrategy = {}; // Refer the next section for detailed documentation on configStrategy
31+
const cache = Cache.getInstance(configStrategy);
32+
33+
const cacheImplementer = cache.cacheInstance;
34+
```
35+
36+
**Note**: To print detailed logs, add `CACHE_DEBUG_ENABLED = '1'` in your env variables.
37+
38+
### Config Strategy
3339
**`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:
40+
41+
An example of the configStrategy is:
3542
```js
3643
configStrategy = {
3744
cache: {
@@ -58,9 +65,8 @@ configStrategy = {
5865
- **namespace**: It is in-memory cache namespace.
5966

6067

61-
<b>Below are the examples of configStrategies:</b>
62-
* Redis
63-
68+
#### Redis Example
69+
Following is an example of redis engine config strategy to be used in initializing Cache.
6470
```js
6571
configStrategy = {
6672
cache: {
@@ -74,8 +80,8 @@ configStrategy = {
7480
}
7581
}
7682
````
77-
* Memcached
78-
83+
#### Memcache Example
84+
Following is an example of memcache engine config strategy to be used in initializing Cache.
7985
```js
8086
configStrategy = {
8187
cache: {
@@ -86,7 +92,8 @@ configStrategy = {
8692
}
8793
}
8894
````
89-
* In-memory
95+
#### In-memory Example
96+
Following is an example of in-memory engine config strategy to be used in initializing Cache.
9097
```js
9198
configStrategy = {
9299
cache: {
@@ -98,20 +105,10 @@ configStrategy = {
98105
}
99106
```
100107

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:
108+
## `cacheImplementer` methods
109+
Irrespective of the caching engine, the methods exposed in `cacheImplementer` have the consistent signature.
112110

113111
### Store and retrieve data in cache using `set` and `get`:
114-
115112
```js
116113
const resolvePromise = function(cacheResponse){
117114
if (cacheResponse.isSuccess()) {
@@ -162,13 +159,7 @@ cacheImplementer.decrement('testCounterKey', 5).then(resolvePromise);
162159

163160
```js
164161
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-
});
162+
cacheImplementer.touch('testKey', 10).then(resolvePromise);
172163
```
173164

174165
## Running test cases

0 commit comments

Comments
 (0)