memory-cache-node
Advanced tools
Comparing version 1.1.2 to 1.2.0
@@ -18,2 +18,3 @@ export declare type ItemValueWrapper<V> = { | ||
retrieveItemValue(itemKey: K): V | undefined; | ||
getItemExpirationTimestampInMillisSinceEpoch(itemKey: K): number | undefined; | ||
removeItem(itemKey: K): void; | ||
@@ -20,0 +21,0 @@ clear(): void; |
@@ -43,2 +43,6 @@ "use strict"; | ||
} | ||
getItemExpirationTimestampInMillisSinceEpoch(itemKey) { | ||
var _a; | ||
return (_a = this.itemKeyToItemValueWrapperMap.get(itemKey)) === null || _a === void 0 ? void 0 : _a.expirationTimestampInMillisSinceEpoch; | ||
} | ||
removeItem(itemKey) { | ||
@@ -45,0 +49,0 @@ if (this.hasItem(itemKey)) { |
@@ -90,2 +90,14 @@ "use strict"; | ||
}); | ||
describe('getItemExpirationTimestampInMillisSinceEpoch', () => { | ||
it('should return the item expiration timestamp if cache contains item with given key', () => { | ||
memoryCache = new MemoryCache_1.default(1, 10); | ||
memoryCache.storeExpiringItem('key', 2, 60); | ||
expect(memoryCache.getItemExpirationTimestampInMillisSinceEpoch('key')) | ||
.toBeGreaterThan(Date.now()); | ||
}); | ||
it('should return undefined if cache does not contain item with given key', () => { | ||
memoryCache = new MemoryCache_1.default(1, 10); | ||
expect(memoryCache.getItemExpirationTimestampInMillisSinceEpoch('key')).toBe(undefined); | ||
}); | ||
}); | ||
describe('removeItem', () => { | ||
@@ -92,0 +104,0 @@ it('should remove the item if cache contains item with given key', () => { |
{ | ||
"name": "memory-cache-node", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "Fast, modern and event loop non-blocking memory cache for Node.js and browse", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -16,3 +16,2 @@ # memory-cache-node | ||
## Table of Contents | ||
@@ -92,2 +91,12 @@ - [Installation](#installation) | ||
### Getting the item expiration timestamp | ||
```ts | ||
import { MemoryCache } from 'memory-cache-node'; | ||
const memoryCache = new MemoryCache<string, number>(600, 1000000); | ||
memoryCache.storePermanentItem('key1', 1); | ||
console.log(memoryCache.getItemExpirationTimestampInMillisSinceEpoch('key1')); // Logs some large number to console | ||
``` | ||
### Removing an item from the memory cache | ||
@@ -134,2 +143,5 @@ ```ts | ||
```ts | ||
`K` is the type of the item key. | ||
`V` is the type of the item value. | ||
class MemoryCache<K, V> { | ||
@@ -142,2 +154,3 @@ constructor(itemsExpirationCheckIntervalInSecs: number, maxItemCount: number); | ||
retrieveItemValue(itemKey: K): V | undefined; | ||
getItemExpirationTimestampInMillisSinceEpoch(itemKey: K): number | undefined; | ||
removeItem(itemKey: K): void; | ||
@@ -149,5 +162,2 @@ clear(): void; | ||
`K` is the type of the item key. | ||
`V` is the type of the item value. | ||
## <a name="license"></a> License | ||
@@ -154,0 +164,0 @@ [MIT](https://github.com/pksilen/memory-cache-node/blob/main/LICENSE) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
53019
306
170