From 3867c1a69429ec23dd85175954790ea3029235fc Mon Sep 17 00:00:00 2001 From: kedarchandrayan Date: Tue, 18 Oct 2022 15:32:41 +0530 Subject: [PATCH 1/2] readme changes before removal of beta flag. --- README.md | 73 ++++++++++++++++++++++++------------------ config/coreConstant.js | 2 +- 2 files changed, 42 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index c80dda1..39bac23 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,22 @@ ![UniCache logo Dark](https://user-images.githubusercontent.com/7627517/195535780-47906a3b-c302-4c59-bb1e-d171914ff1bd.png) -[![Latest version](https://img.shields.io/npm/v/@plgworks/cache.svg?maxAge=3600)][npm] +[![Latest version](https://img.shields.io/npm/v/@plgworks/unicache.svg?maxAge=3600)][npm] [npm]: https://www.npmjs.com/package/@plgworks/unicache -UniCache is an NPM package that provides singleton interface and behavior for [Memcached](https://memcached.org/), [Redis](https://redis.io/docs/) and -In-memory caching. Easily interact or switch between them in minutes! +UniCache is an NPM package that provides unified / singleton interface and behavior for [Memcached](https://memcached.org/), +[Redis](https://redis.io/docs/) and In-memory caching. Easily interact or switch between them in minutes! ## Why UniCache? -- 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. +- UniCache abstracts the unnecessary deviations between the base NPM packages of Memcached and Redis, in turn helping you +learn about and interact with 3 different caching engines (Memcached, Redis and In-memory) all at once. - Singleton interface of UniCache is not only compatible with Memcached and Redis but also for In-Memory cache. -- 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. -- 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. -- 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. +- 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. Even exceptions are given out consistently. +- When using multiple caching engines simultaneously or want to switch between them, consistent output from UniCache +will help in faster development. +- 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. - UniCache is thoroughly tested and is fully compatible with AWS ElastiCache for Redis and AWS ElastiCache for Memcached. ## Prerequisites @@ -29,7 +33,8 @@ npm install @plgworks/unicache --save ``` ## Initialize -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. +While using the package, create a singleton object of UniCache for each caching engines and then use it across the application. +Example snippet for the UniCache singleton object initialization is given below. ```js // 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. const cacheProvider = require('path-to-your-uni-cache-singleton-provider'); const cacheImplementer = cacheProvider.cacheInstance; -cacheImplementer.set('testKey', 'testValue', 5000); -cacheImplementer.get('testKey'); +cacheImplementer.set('testKey', 'testValue', 5000).then(console.log); +cacheImplementer.get('testKey').then(console.log); ``` -**Note**: To print detailed logs, add `CACHE_DEBUG_ENABLED = '1'` in your env variables. +**Note**: To print detailed logs, add `UNICACHE_DEBUG_ENABLED = '1'` in the ENV variables. ### Config Strategy -**`configStrategy`** is a mandatory parameter which specifies the configuration strategy to be used for the caching engine. +**`configStrategy`** is a mandatory parameter which specifies the configuration to be used for the caching engine. Using the `engine` property, you can select which caching engine to use. An example of the configStrategy is: @@ -68,7 +73,7 @@ const configStrategy = { ``` #### Redis Config Strategy -Following is the redis engine config strategy to be used in initializing UniCache. +Following is how the config strategy looks for redis caching engine. ```js const configStrategy = { engine: "redis", @@ -80,16 +85,16 @@ const configStrategy = { consistentBehavior: "1" } ```` -- **engine**: redis caching engine to be used. -- **host**: Host of the redis caching engine. -- **port**: Port on which redis caching engine is running. -- **password**: Redis caching engine password. -- **enableTsl**: This field is used to enable tsl. -- **defaultTtl**: Default cache expiry time in sec. -- **consistentBehavior**: This field is required to create cache instance key. +- **engine**: Pass value `redis` for using UniCahce with Redis. +- **host**: Host of the Redis server. +- **port**: Port of the Redis server. +- **password**: Password for auth with Redis server. +- **enableTsl**: Pass '1' for enabling TSL. Otherwise '0' +- **defaultTtl**: Default time to live (TTL) for cache in seconds. +- **consistentBehavior**: Pass '1' to use the consistent behaviour accross various caching engines option. Otherwise '0'. #### Memcache Config Strategy -Following is the memcache engine config strategy to be used in initializing UniCache. +Following is how the config strategy looks for Memcache caching engine. ```js const configStrategy = { engine: "memcached", @@ -98,13 +103,13 @@ const configStrategy = { consistentBehavior: "1" } ```` -- **engine**: memcached caching engine to be used. -- **servers**: servers is an array of memcached servers. -- **defaultTtl**: Default cache expiry time in sec. -- **consistentBehavior**: This field is required to create cache instance key. +- **engine**: Pass value `memcached` for using UniCahce with Memcache. +- **servers**: Servers is an array of memcached servers' hosts. +- **defaultTtl**: Default time to live (TTL) for cache in seconds. +- **consistentBehavior**: Pass '1' to use the consistent behaviour accross various caching engines option. Otherwise '0'. #### In-Memory Config Strategy -Following is the in-memory engine config strategy to be used in initializing UniCache. +Following is how the config strategy looks for In-memory caching engine. ```js const configStrategy = { engine: "none", @@ -113,13 +118,14 @@ const configStrategy = { consistentBehavior: "1" } ``` -- **engine**: For in-memory cache engine parameter will be `none`. -- **namespace**: It is in-memory cache namespace. -- **defaultTtl**: Default cache expiry time in sec. -- **consistentBehavior**: This field is required to create cache instance key. +- **engine**: Pass value `none` for using UniCahce with In-memory cache. +- **namespace**: In-memory cache namespace. You can segregate cache keys in the same machine with different namespaces. +- **defaultTtl**: Default time to live (TTL) for cache in seconds. +- **consistentBehavior**: Pass '1' to use the consistent behaviour accross various caching engines option. Otherwise '0'. ## `cacheImplementer` methods -Irrespective of the caching engine, the methods exposed in `cacheImplementer` have the consistent signature. +Irrespective of the caching engine, the methods exposed in `cacheImplementer` have the consistent signature, +i.e. singleton interface implementation. ### Store and retrieve data in cache using `set` and `get`: ```js @@ -177,14 +183,17 @@ cacheImplementer.touch('testKey', 10).then(resolvePromise); ## Test Cases Test cases cover all the 3 caching engines. Also a coverage report is generated at the end. +Running test cases is a 2 step process. -### Step 1: Start Cache engines +### Step 1: Start Cache Engines Following processes are needed for running test cases. + * Start Redis on 2 ports - 6380 and 6381 as needed by the test cases. ```shell script redis-server --port 6380 redis-server --port 6381 ``` + * Start Memcached on 4 ports - 11212,11213,11214 and 11215 as needed by the test cases. ```shell script memcached -p 11212 -d diff --git a/config/coreConstant.js b/config/coreConstant.js index 4997927..3c3851b 100644 --- a/config/coreConstant.js +++ b/config/coreConstant.js @@ -20,7 +20,7 @@ class CoreConstant { */ get DEBUG_ENABLED() { // eslint-disable-next-line no-process-env - return process.env.CACHE_DEBUG_ENABLED; + return process.env.UNICACHE_DEBUG_ENABLED; } } From 6ac856e1e6c8fc6ce33b1efe8193fc441e59fbda Mon Sep 17 00:00:00 2001 From: kedarchandrayan Date: Tue, 18 Oct 2022 15:35:25 +0530 Subject: [PATCH 2/2] removal of beta. --- CHANGELOG.md | 2 +- README.md | 2 +- VERSION | 2 +- package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d0523a..305814c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,3 @@ -## UniCache v1.0.0-beta.1 +## UniCache v1.0.0 - First release of UniCache having support for 3 caching engines - Memcached, Redis and In-memory Cache - Test case coverage improved to 95%. diff --git a/README.md b/README.md index 39bac23..a326747 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [npm]: https://www.npmjs.com/package/@plgworks/unicache -UniCache is an NPM package that provides unified / singleton interface and behavior for [Memcached](https://memcached.org/), +UniCache is an open-source NPM package that provides unified / singleton interface and behavior for [Memcached](https://memcached.org/), [Redis](https://redis.io/docs/) and In-memory caching. Easily interact or switch between them in minutes! ## Why UniCache? diff --git a/VERSION b/VERSION index ffbc993..3eefcb9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.0-beta.1 +1.0.0 diff --git a/package.json b/package.json index a740785..63efe45 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@plgworks/unicache", - "version": "1.0.0-beta.1", + "version": "1.0.0", "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!", "main": "index.js", "scripts": {