Skip to content

Commit 6bfa643

Browse files
authored
Merge pull request #15 from PLG-Works/release-1.0
2 parents 987feca + 87917d0 commit 6bfa643

5 files changed

Lines changed: 45 additions & 36 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
## UniCache v1.0.0-beta.1
1+
## UniCache v1.0.0
22
- First release of UniCache having support for 3 caching engines - Memcached, Redis and In-memory Cache
33
- Test case coverage improved to 95%.

README.md

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
![UniCache logo Dark](https://user-images.githubusercontent.com/7627517/195535780-47906a3b-c302-4c59-bb1e-d171914ff1bd.png)
22

3-
[![Latest version](https://img.shields.io/npm/v/@plgworks/cache.svg?maxAge=3600)][npm]
3+
[![Latest version](https://img.shields.io/npm/v/@plgworks/unicache.svg?maxAge=3600)][npm]
44

55
[npm]: https://www.npmjs.com/package/@plgworks/unicache
66

7-
UniCache is an NPM package that provides singleton interface and behavior for [Memcached](https://memcached.org/), [Redis](https://redis.io/docs/) and
8-
In-memory caching. Easily interact or switch between them in minutes!
7+
UniCache is an open-source NPM package that provides unified / singleton interface and behavior for [Memcached](https://memcached.org/),
8+
[Redis](https://redis.io/docs/) and In-memory caching. Easily interact or switch between them in minutes!
99

1010
## Why UniCache?
11-
- UniCache abstracts the unnecessary deviations between the base packages, in turn helping you learn about and interact with 3 different caching engines (Memcached, Redis and In-memory) all at once.
11+
- UniCache abstracts the unnecessary deviations between the base NPM packages of Memcached and Redis, in turn helping you
12+
learn about and interact with 3 different caching engines (Memcached, Redis and In-memory) all at once.
1213
- Singleton interface of UniCache is not only compatible with Memcached and Redis but also for In-Memory cache.
13-
- If your backend is interacting with multiple caching engines, UniCache helps developers to reduce translation layer for input and output - thus reducing development time and effort.
14-
- When using multiple caching engines simultaneously or want to switch between them, consistent output from UniCache will help in faster development. Even exceptions are given out consistently.
15-
- Be rest assured that your code will not need any further changes in order to use the upcoming base NPM package versions. UniCache will take care of it.
14+
- If your backend is interacting with multiple caching engines, UniCache helps developers to reduce translation layer
15+
for input and output - thus reducing development time and effort. Even exceptions are given out consistently.
16+
- When using multiple caching engines simultaneously or want to switch between them, consistent output from UniCache
17+
will help in faster development.
18+
- Be rest assured that your code will not need any further changes in order to use the upcoming base NPM package versions.
19+
UniCache will take care of it.
1620
- UniCache is thoroughly tested and is fully compatible with AWS ElastiCache for Redis and AWS ElastiCache for Memcached.
1721

1822
## Prerequisites
@@ -29,7 +33,8 @@ npm install @plgworks/unicache --save
2933
```
3034

3135
## Initialize
32-
While using the package, create a singleton object of UniCache and then use it across the application. Example snippet for the UniCache singleton object is given below.
36+
While using the package, create a singleton object of UniCache for each caching engines and then use it across the application.
37+
Example snippet for the UniCache singleton object initialization is given below.
3338

3439
```js
3540
// Include the following snippet in a separate file, which can be required all accross the code to get unicache instance.
@@ -49,14 +54,14 @@ The singleton object can be used as given below.
4954
const cacheProvider = require('path-to-your-uni-cache-singleton-provider');
5055
const cacheImplementer = cacheProvider.cacheInstance;
5156

52-
cacheImplementer.set('testKey', 'testValue', 5000);
53-
cacheImplementer.get('testKey');
57+
cacheImplementer.set('testKey', 'testValue', 5000).then(console.log);
58+
cacheImplementer.get('testKey').then(console.log);
5459
```
5560

56-
**Note**: To print detailed logs, add `CACHE_DEBUG_ENABLED = '1'` in your env variables.
61+
**Note**: To print detailed logs, add `UNICACHE_DEBUG_ENABLED = '1'` in the ENV variables.
5762

5863
### Config Strategy
59-
**`configStrategy`** is a mandatory parameter which specifies the configuration strategy to be used for the caching engine.
64+
**`configStrategy`** is a mandatory parameter which specifies the configuration to be used for the caching engine.
6065
Using the `engine` property, you can select which caching engine to use.
6166

6267
An example of the configStrategy is:
@@ -68,7 +73,7 @@ const configStrategy = {
6873
```
6974

7075
#### Redis Config Strategy
71-
Following is the redis engine config strategy to be used in initializing UniCache.
76+
Following is how the config strategy looks for redis caching engine.
7277
```js
7378
const configStrategy = {
7479
engine: "redis",
@@ -80,16 +85,16 @@ const configStrategy = {
8085
consistentBehavior: "1"
8186
}
8287
````
83-
- **engine**: redis caching engine to be used.
84-
- **host**: Host of the redis caching engine.
85-
- **port**: Port on which redis caching engine is running.
86-
- **password**: Redis caching engine password.
87-
- **enableTsl**: This field is used to enable tsl.
88-
- **defaultTtl**: Default cache expiry time in sec.
89-
- **consistentBehavior**: This field is required to create cache instance key.
88+
- **engine**: Pass value `redis` for using UniCahce with Redis.
89+
- **host**: Host of the Redis server.
90+
- **port**: Port of the Redis server.
91+
- **password**: Password for auth with Redis server.
92+
- **enableTsl**: Pass '1' for enabling TSL. Otherwise '0'
93+
- **defaultTtl**: Default time to live (TTL) for cache in seconds.
94+
- **consistentBehavior**: Pass '1' to use the consistent behaviour accross various caching engines option. Otherwise '0'.
9095

9196
#### Memcache Config Strategy
92-
Following is the memcache engine config strategy to be used in initializing UniCache.
97+
Following is how the config strategy looks for Memcache caching engine.
9398
```js
9499
const configStrategy = {
95100
engine: "memcached",
@@ -98,13 +103,13 @@ const configStrategy = {
98103
consistentBehavior: "1"
99104
}
100105
````
101-
- **engine**: memcached caching engine to be used.
102-
- **servers**: servers is an array of memcached servers.
103-
- **defaultTtl**: Default cache expiry time in sec.
104-
- **consistentBehavior**: This field is required to create cache instance key.
106+
- **engine**: Pass value `memcached` for using UniCahce with Memcache.
107+
- **servers**: Servers is an array of memcached servers' hosts.
108+
- **defaultTtl**: Default time to live (TTL) for cache in seconds.
109+
- **consistentBehavior**: Pass '1' to use the consistent behaviour accross various caching engines option. Otherwise '0'.
105110
106111
#### In-Memory Config Strategy
107-
Following is the in-memory engine config strategy to be used in initializing UniCache.
112+
Following is how the config strategy looks for In-memory caching engine.
108113
```js
109114
const configStrategy = {
110115
engine: "none",
@@ -113,13 +118,14 @@ const configStrategy = {
113118
consistentBehavior: "1"
114119
}
115120
```
116-
- **engine**: For in-memory cache engine parameter will be `none`.
117-
- **namespace**: It is in-memory cache namespace.
118-
- **defaultTtl**: Default cache expiry time in sec.
119-
- **consistentBehavior**: This field is required to create cache instance key.
121+
- **engine**: Pass value `none` for using UniCahce with In-memory cache.
122+
- **namespace**: In-memory cache namespace. You can segregate cache keys in the same machine with different namespaces.
123+
- **defaultTtl**: Default time to live (TTL) for cache in seconds.
124+
- **consistentBehavior**: Pass '1' to use the consistent behaviour accross various caching engines option. Otherwise '0'.
120125

121126
## `cacheImplementer` methods
122-
Irrespective of the caching engine, the methods exposed in `cacheImplementer` have the consistent signature.
127+
Irrespective of the caching engine, the methods exposed in `cacheImplementer` have the consistent signature,
128+
i.e. singleton interface implementation.
123129

124130
### Store and retrieve data in cache using `set` and `get`:
125131
```js
@@ -177,14 +183,17 @@ cacheImplementer.touch('testKey', 10).then(resolvePromise);
177183

178184
## Test Cases
179185
Test cases cover all the 3 caching engines. Also a coverage report is generated at the end.
186+
Running test cases is a 2 step process.
180187

181-
### Step 1: Start Cache engines
188+
### Step 1: Start Cache Engines
182189
Following processes are needed for running test cases.
190+
183191
* Start Redis on 2 ports - 6380 and 6381 as needed by the test cases.
184192
```shell script
185193
redis-server --port 6380
186194
redis-server --port 6381
187195
```
196+
188197
* Start Memcached on 4 ports - 11212,11213,11214 and 11215 as needed by the test cases.
189198
```shell script
190199
memcached -p 11212 -d

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.0-beta.1
1+
1.0.0

config/coreConstant.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class CoreConstant {
2020
*/
2121
get DEBUG_ENABLED() {
2222
// eslint-disable-next-line no-process-env
23-
return process.env.CACHE_DEBUG_ENABLED;
23+
return process.env.UNICACHE_DEBUG_ENABLED;
2424
}
2525
}
2626

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@plgworks/unicache",
3-
"version": "1.0.0-beta.1",
3+
"version": "1.0.0",
44
"description": "UniCache is an NPM package that provides singleton interface and behavior for Memcached, Redis and In-memory caching. Easily interact or switch between them in minutes!",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)