@acuris/leprechaun-cache
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -33,3 +33,3 @@ "use strict"; | ||
try { | ||
promise = this.doGet(this.keyPrefix + key, ttlInMilliseconds); | ||
promise = this.doGet(key, ttlInMilliseconds); | ||
this.inProgress.set(key, promise); | ||
@@ -45,3 +45,3 @@ return await promise; | ||
async doGet(key, ttl) { | ||
const result = await this.cacheStore.get(key); | ||
const result = await this.cacheStore.get(this.keyPrefix + key); | ||
if (!result) { | ||
@@ -68,3 +68,3 @@ return this.updateCache(key, ttl, true); | ||
do { | ||
lock.lockId = (await this.cacheStore.lock(key, this.lockTTL)) || ''; | ||
lock.lockId = (await this.cacheStore.lock(this.keyPrefix + key, this.lockTTL)) || ''; | ||
if (lock.lockId) { | ||
@@ -82,3 +82,3 @@ break; | ||
: { | ||
lockId: (await this.cacheStore.lock(key, this.lockTTL)) || '', | ||
lockId: (await this.cacheStore.lock(this.keyPrefix + key, this.lockTTL)) || '', | ||
didSpin: false | ||
@@ -94,5 +94,5 @@ }; | ||
//If we spun while getting the lock, then get the updated version (hopefully updated by another process) | ||
const result = await this.cacheStore.get(key); | ||
const result = await this.cacheStore.get(this.keyPrefix + key); | ||
if (result && result.data) { | ||
await this.cacheStore.unlock(key, lock.lockId); | ||
await this.cacheStore.unlock(this.keyPrefix + key, lock.lockId); | ||
return result.data; | ||
@@ -111,3 +111,3 @@ } | ||
try { | ||
await this.cacheStore.set(key, cacheData, this.hardTTL); | ||
await this.cacheStore.set(this.keyPrefix + key, cacheData, this.hardTTL); | ||
} | ||
@@ -119,3 +119,3 @@ catch (e) { | ||
try { | ||
await this.cacheStore.unlock(key, lock.lockId); | ||
await this.cacheStore.unlock(this.keyPrefix + key, lock.lockId); | ||
} | ||
@@ -122,0 +122,0 @@ catch (e) { |
{ | ||
"name": "@acuris/leprechaun-cache", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "Caching library that supports double checked caching and stale returns to avoid stampede and slow responses", |
@@ -62,3 +62,3 @@ import { CacheStore, Cacheable, OnCacheMiss, LeprechaunCacheOptions, CacheItem } from './types' | ||
try { | ||
promise = this.doGet(this.keyPrefix + key, ttlInMilliseconds) | ||
promise = this.doGet(key, ttlInMilliseconds) | ||
this.inProgress.set(key, promise) | ||
@@ -74,3 +74,3 @@ return await promise | ||
private async doGet(key: string, ttl: number): Promise<T> { | ||
const result = await this.cacheStore.get(key) | ||
const result = await this.cacheStore.get(this.keyPrefix + key) | ||
if (!result) { | ||
@@ -97,3 +97,3 @@ return this.updateCache(key, ttl, true) | ||
do { | ||
lock.lockId = (await this.cacheStore.lock(key, this.lockTTL)) || '' | ||
lock.lockId = (await this.cacheStore.lock(this.keyPrefix + key, this.lockTTL)) || '' | ||
if (lock.lockId) { | ||
@@ -112,3 +112,3 @@ break | ||
: { | ||
lockId: (await this.cacheStore.lock(key, this.lockTTL)) || '', | ||
lockId: (await this.cacheStore.lock(this.keyPrefix + key, this.lockTTL)) || '', | ||
didSpin: false | ||
@@ -127,5 +127,5 @@ } | ||
//If we spun while getting the lock, then get the updated version (hopefully updated by another process) | ||
const result = await this.cacheStore.get(key) | ||
const result = await this.cacheStore.get(this.keyPrefix + key) | ||
if (result && result.data) { | ||
await this.cacheStore.unlock(key, lock.lockId) | ||
await this.cacheStore.unlock(this.keyPrefix + key, lock.lockId) | ||
return result.data | ||
@@ -152,3 +152,3 @@ } | ||
try { | ||
await this.cacheStore.set(key, cacheData, this.hardTTL) | ||
await this.cacheStore.set(this.keyPrefix + key, cacheData, this.hardTTL) | ||
} catch (e) { | ||
@@ -159,3 +159,3 @@ this.onBackgroundError(e) | ||
try { | ||
await this.cacheStore.unlock(key, lock.lockId) | ||
await this.cacheStore.unlock(this.keyPrefix + key, lock.lockId) | ||
} catch (e) { | ||
@@ -162,0 +162,0 @@ this.onBackgroundError(e) |
Sorry, the diff of this file is not supported yet
33576
26