@@ -12,31 +12,55 @@ The caching engines implemented are:
1212* [ Memcached] ( https://memcached.org/ )
1313* [ Redis] ( https://redis.io/docs/ )
1414* In-memory (use with single threaded process in development mode only)
15+ ## Why Cache?
16+ Implementation method varies according to caching systems.
17+ So implementing different caching systems is always a overhead for developer.
18+ Our package solve this problem by providing common wrapper methods for memcached, redis and in-memory caching system.
1519
16- # Install NPM
20+ ## Prerequisites
21+ Required caching engine for the use case must be installed and up.
22+ Refer [ memcached] ( https://gist.github.com/tomysmile/ba6c0ba4488ea51e6423d492985a7953 ) and [ redis] ( https://flaviocopes.com/redis-installation/ ) installation guide.
23+
24+ ## Install NPM
1725``` bash
1826npm install @plgworks/cache --save
1927```
2028
21- # Initialize
22- There is 1 parameter required while creating the cache implementer.
29+ ## Initialize
2330
24- * First parameter is mandatory and it specifies the configuration strategy to be used. An example of the configStrategy is:
31+ #### Cache Initialization Params
32+ ** ` configStrategy ` ** is a mandatory parameter which specifies the configuration strategy to be used for a particular cache engine.
33+ An example of the configStrategy is:
2534``` js
2635configStrategy = {
2736 cache: {
28- engine: " none/redis/memcache"
37+ engine: " none/redis/memcached" ,
38+ host: " " ,
39+ port: " " ,
40+ password: " " ,
41+ enableTsl: " " ,
42+ defaultTtl: 10000 ,
43+ consistentBehavior: " " ,
44+ servers: [],
45+ namespace: " "
2946 }
3047};
3148```
49+ - ** engine** : redis, memcached are different types of caching engine. For in-memory cache engine parameter will be ` none ` .
50+ - ** host** : Host of the redis caching engine.
51+ - ** port** : Port on which redis caching engine is running.
52+ - ** password** : Redis caching engine password.
53+ - ** enableTsl** : This field is used to enable tsl.
54+ - ** defaultTtl** : Default cache expiry time in sec.
55+ - ** consistentBehavior** : This field is required to create cache instance key.
56+ - ** servers** : servers is an array of memcached servers.
57+ - ** namespace** : It is in-memory cache namespace.
58+
59+
60+ <b >Below are the examples of configStrategies:</b >
61+ * Redis
3262
33- <b >Below are the examples:</b >
34- ``` js
35- // import the cache module
36- const cache = require (' @plgworks/cache' );
37- ```
3863``` js
39- // configStrategy for redis engine
4064configStrategy = {
4165 cache: {
4266 engine: " redis" ,
@@ -49,9 +73,9 @@ configStrategy = {
4973 }
5074}
5175````
76+ * Memcached
5277
5378` ` ` js
54- // configStrategy for memcached engine
5579configStrategy = {
5680 cache: {
5781 engine: "memcached",
@@ -61,8 +85,8 @@ configStrategy = {
6185 }
6286}
6387` ` ` `
88+ * In-memory
6489` ` ` js
65- // configStrategy for in-memory engine
6690configStrategy = {
6791 cache: {
6892 engine: " none" ,
@@ -72,7 +96,7 @@ configStrategy = {
7296 }
7397}
7498```
75- # Examples:
99+ ## Examples:
76100
77101#### Create Cache Object:
78102
@@ -182,28 +206,31 @@ cacheImplementer.touch('testKey', 10).then(function(cacheResponse){
182206 }
183207 });
184208```
185- ### Running test cases
209+ ## Running test cases
186210##### Set environment variables of particular cache engine for which you want to run the tests.
187- ````
188- # For Memcached
189- source test/env/memcached.sh
190211
191- # For Redis
212+ * Redis
213+ ````
192214source test/env/redis.sh
193-
194- # For In-memory
215+ ````
216+ * Memcached
217+ ````
218+ source test/env/memcached.sh
219+ ````
220+ * In-memory
221+ ````
195222source test/env/inMemory.sh
196223````
197224##### Cache engines must be running on the specified ports.
198225
199- * Memcached (11212,11213,11214,11215)
200- ````
201- memcached -p 11212 -d
202- ````
203226* Redis (6380,6381)
204227````
205228redis-server --port 6380
206229````
230+ * Memcached (11212,11213,11214,11215)
231+ ````
232+ memcached -p 11212 -d
233+ ````
207234##### Run tests
208235````
209236./node_modules/.bin/mocha --recursive "./test/*.js"
0 commit comments