From 7047cf4666a452df0d25c842af7d7edabaa10c96 Mon Sep 17 00:00:00 2001 From: shahar-y Date: Mon, 14 Mar 2022 18:03:56 +0300 Subject: [PATCH 1/4] 1.0.6 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4e44e68..1e1f525 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "try-cache", - "version": "1.0.5", + "version": "1.0.6", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 939cde5..dbd874d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "try-cache", "description": "An auto-caching npm package for super-fast retrieval of less-consistant data", - "version": "1.0.5", + "version": "1.0.6", "main": "dist/index.js", "types": "dist/index.d.ts", "scripts": { From 3cc322c44eabb506301f2597b087a680254b5416 Mon Sep 17 00:00:00 2001 From: shahar-y Date: Mon, 21 Mar 2022 16:16:23 +0300 Subject: [PATCH 2/4] updated README and exported members --- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++- docker-compose.yml | 7 ------- src/index.ts | 4 +++- 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 469e097..df21410 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,50 @@ # try-cache -An auto-caching npm package for super-fast retrieval of data that doesn't have to be consistant. +![npm](https://img.shields.io/npm/v/try-cache?color=green) +![NPM](https://img.shields.io/npm/l/try-cache) +![Snyk Vulnerabilities for npm package](https://img.shields.io/snyk/vulnerabilities/npm/try-cache) +![npm](https://img.shields.io/npm/dt/try-cache) + +An auto-caching npm package for super-fast retrieval of data that doesn't have to be atomicly consistant, +allowing automatic cache update and expiration according to the user's needs. + +## Installation + +`npm i --save try-cache` + +## Usage Example + +``` +import { TryCache } from 'try-cache'; + +// Sets the expiration to 20 seconds, and alerts on calls +const cb = new TryCache('redis://localhost:6379', { silent: false, expire: 20 }); + +// Initiates the connection to redis +await cb.initTryCache(); + +// Should take 3 seconds +const res1 = await cb.tryCache('myKey', () => dummyDB(2, 7)); +console.log('First time result:', res1); + +// Should take a few ms because cahe is saved +const res2 = await cb.tryCache('myKey', () => dummyDB(2, 7)); +console.log('Second time result:', res2); + + +// dummyDB simulates a database call +async function dummyDB(x: number, y: number) { + await sleep(3000); + + return { x, y }; +} +``` + +## To run the package locally with the example: + +1. Run the docker-compose (or run redis locally manually): `docker-compose -f "src\miscellaneous\docker-compose.yml" up -d --build` +2. Run the example: `npm run example` + +The output should show the different use-cases of the package (with and without cache at the beginning) + +- Notice! The third and fourth runs should successfully fail as they simulate the failure of the original db retrieval function. diff --git a/docker-compose.yml b/docker-compose.yml index 108b2c0..802a8d9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,11 +6,4 @@ services: - '6379:6379' expose: - 6379 - - try-cache: - container_name: try-cache - build: . - ports: - - '3000:3000' - restart: always # docker-compose -f "src\miscellaneous\docker-compose.yml" up -d --build diff --git a/src/index.ts b/src/index.ts index 389b960..cb1df2c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,7 @@ import { defaults } from './defaults'; export let logger: Logger; -export class TryCache { +class TryCache { options: TCOptions; redisConnectionString: string; @@ -109,3 +109,5 @@ export class TryCache { } } } + +export { TryCache, TCOptions, OperationOptions }; From 2aa95a64e295f2753b61aeb760e19abfe03d2262 Mon Sep 17 00:00:00 2001 From: shahar-y Date: Mon, 21 Mar 2022 16:16:45 +0300 Subject: [PATCH 3/4] 1.0.7 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1e1f525..cf068dd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "try-cache", - "version": "1.0.6", + "version": "1.0.7", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index dbd874d..15cce8f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "try-cache", "description": "An auto-caching npm package for super-fast retrieval of less-consistant data", - "version": "1.0.6", + "version": "1.0.7", "main": "dist/index.js", "types": "dist/index.d.ts", "scripts": { From 37bc330959f170bbae1f8fa2f6295c7a1cbc09e8 Mon Sep 17 00:00:00 2001 From: shahar-y Date: Mon, 21 Mar 2022 16:19:49 +0300 Subject: [PATCH 4/4] added keywords --- package.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 15cce8f..87c67fe 100644 --- a/package.json +++ b/package.json @@ -16,10 +16,13 @@ "url": "git+https://github.com/Shahar-Y/try-cache.git" }, "keywords": [ - "redis", + "try-cache", + "try", "cache", + "node", + "redis", "async", - "efficiency", + "performance", "db", "database" ],