@luvio/service-cache
Advanced tools
Comparing version 5.26.0 to 5.27.0
@@ -0,1 +1,2 @@ | ||
import { type DeepReadonly } from '@luvio/utils'; | ||
import { type Key, type KeySet } from './keys'; | ||
@@ -41,3 +42,5 @@ /** | ||
export type Cache = { | ||
get<T>(key: Key): CacheEntry<T> | undefined; | ||
get<T>(key: Key, options?: { | ||
copy: boolean; | ||
}): DeepReadonly<CacheEntry<T>> | CacheEntry<T> | undefined; | ||
set<T>(key: Key, value: CacheEntry<T>): void; | ||
@@ -44,0 +47,0 @@ delete(key: Key): void; |
@@ -0,1 +1,2 @@ | ||
import { type DeepReadonly } from '@luvio/utils'; | ||
import { type Key, type KeySet } from './keys'; | ||
@@ -7,8 +8,15 @@ import type { CacheEntry, Cache, FilteredCache, RecordableCache, FilterPredicate } from './cache'; | ||
/** | ||
* Returns the cache entry at the specified key; undefined if no | ||
* Returns a cache entry at the specified key; undefined if no | ||
* such entry exists. | ||
* | ||
* @param key store key | ||
* @param [options] options for get (e.g. copy for deep copy) | ||
*/ | ||
get<T>(key: Key): CacheEntry<T> | undefined; | ||
get<T>(key: Key): DeepReadonly<CacheEntry<T>> | undefined; | ||
get<T>(key: Key, options: { | ||
copy: true; | ||
}): CacheEntry<T> | undefined; | ||
get<T>(key: Key, options: { | ||
copy: false; | ||
}): DeepReadonly<CacheEntry<T>> | undefined; | ||
/** | ||
@@ -15,0 +23,0 @@ * Adds the specified key/value to the cache. |
@@ -0,1 +1,2 @@ | ||
import { type DeepReadonly } from '@luvio/utils'; | ||
import { type Key, type KeySet, KeySetImpl } from './keys'; | ||
@@ -13,3 +14,9 @@ import type { CacheEntry, Cache, RecordableCache, FilteredCache, FilterPredicate } from './cache'; | ||
delete(key: Key): void; | ||
get<T>(key: Key): CacheEntry<T> | undefined; | ||
get<T>(key: Key): DeepReadonly<CacheEntry<T>> | undefined; | ||
get<T>(key: Key, options: { | ||
copy: true; | ||
}): CacheEntry<T> | undefined; | ||
get<T>(key: Key, options: { | ||
copy: false; | ||
}): DeepReadonly<CacheEntry<T>> | undefined; | ||
set<T>(key: Key, value: CacheEntry<T>): void; | ||
@@ -30,3 +37,9 @@ length(): number; | ||
delete(key: Key): void; | ||
get<T>(key: Key): CacheEntry<T> | undefined; | ||
get<T>(key: Key): DeepReadonly<CacheEntry<T>> | undefined; | ||
get<T>(key: Key, options: { | ||
copy: true; | ||
}): CacheEntry<T> | undefined; | ||
get<T>(key: Key, options: { | ||
copy: false; | ||
}): DeepReadonly<CacheEntry<T>> | undefined; | ||
set<T>(key: Key, value: CacheEntry<T>): void; | ||
@@ -33,0 +46,0 @@ length(): number; |
@@ -7,2 +7,4 @@ /** | ||
import { deepCopy } from '@luvio/utils'; | ||
/** | ||
@@ -65,2 +67,3 @@ * A collection of keys, in no particular order. | ||
/* eslint-disable no-dupe-class-members */ | ||
/** | ||
@@ -80,3 +83,3 @@ A utility class for recording actions made on a cache. | ||
} | ||
get(key) { | ||
get(key, options) { | ||
this.keysRead.add(key); | ||
@@ -87,2 +90,5 @@ const value = this.baseCache.get(key); | ||
} | ||
if (options === null || options === void 0 ? void 0 : options.copy) { | ||
return deepCopy(value); | ||
} | ||
return value; | ||
@@ -121,6 +127,9 @@ } | ||
} | ||
get(key) { | ||
get(key, options) { | ||
const result = this.baseCache.get(key); | ||
// if we're chaining filtered caches together, then it's possible the result will be undefined here | ||
if (result && this.predicate(key, result)) { | ||
if (options === null || options === void 0 ? void 0 : options.copy) { | ||
return deepCopy(result); | ||
} | ||
return result; | ||
@@ -162,2 +171,3 @@ } | ||
/* eslint-disable no-dupe-class-members */ | ||
class DefaultCache { | ||
@@ -167,9 +177,6 @@ constructor() { | ||
} | ||
/** | ||
* Returns the cache entry at the specified key; undefined if no | ||
* such entry exists. | ||
* | ||
* @param key store key | ||
*/ | ||
get(key) { | ||
get(key, options) { | ||
if (options === null || options === void 0 ? void 0 : options.copy) { | ||
return deepCopy(this.data[key]); | ||
} | ||
return this.data[key]; | ||
@@ -176,0 +183,0 @@ } |
@@ -0,1 +1,2 @@ | ||
import { type DeepReadonly } from '@luvio/utils'; | ||
import { type Key, type KeySet } from './keys'; | ||
@@ -41,3 +42,5 @@ /** | ||
export type Cache = { | ||
get<T>(key: Key): CacheEntry<T> | undefined; | ||
get<T>(key: Key, options?: { | ||
copy: boolean; | ||
}): DeepReadonly<CacheEntry<T>> | CacheEntry<T> | undefined; | ||
set<T>(key: Key, value: CacheEntry<T>): void; | ||
@@ -44,0 +47,0 @@ delete(key: Key): void; |
@@ -0,1 +1,2 @@ | ||
import { type DeepReadonly } from '@luvio/utils'; | ||
import { type Key, type KeySet } from './keys'; | ||
@@ -7,8 +8,15 @@ import type { CacheEntry, Cache, FilteredCache, RecordableCache, FilterPredicate } from './cache'; | ||
/** | ||
* Returns the cache entry at the specified key; undefined if no | ||
* Returns a cache entry at the specified key; undefined if no | ||
* such entry exists. | ||
* | ||
* @param key store key | ||
* @param [options] options for get (e.g. copy for deep copy) | ||
*/ | ||
get<T>(key: Key): CacheEntry<T> | undefined; | ||
get<T>(key: Key): DeepReadonly<CacheEntry<T>> | undefined; | ||
get<T>(key: Key, options: { | ||
copy: true; | ||
}): CacheEntry<T> | undefined; | ||
get<T>(key: Key, options: { | ||
copy: false; | ||
}): DeepReadonly<CacheEntry<T>> | undefined; | ||
/** | ||
@@ -15,0 +23,0 @@ * Adds the specified key/value to the cache. |
@@ -0,1 +1,2 @@ | ||
import { type DeepReadonly } from '@luvio/utils'; | ||
import { type Key, type KeySet, KeySetImpl } from './keys'; | ||
@@ -13,3 +14,9 @@ import type { CacheEntry, Cache, RecordableCache, FilteredCache, FilterPredicate } from './cache'; | ||
delete(key: Key): void; | ||
get<T>(key: Key): CacheEntry<T> | undefined; | ||
get<T>(key: Key): DeepReadonly<CacheEntry<T>> | undefined; | ||
get<T>(key: Key, options: { | ||
copy: true; | ||
}): CacheEntry<T> | undefined; | ||
get<T>(key: Key, options: { | ||
copy: false; | ||
}): DeepReadonly<CacheEntry<T>> | undefined; | ||
set<T>(key: Key, value: CacheEntry<T>): void; | ||
@@ -30,3 +37,9 @@ length(): number; | ||
delete(key: Key): void; | ||
get<T>(key: Key): CacheEntry<T> | undefined; | ||
get<T>(key: Key): DeepReadonly<CacheEntry<T>> | undefined; | ||
get<T>(key: Key, options: { | ||
copy: true; | ||
}): CacheEntry<T> | undefined; | ||
get<T>(key: Key, options: { | ||
copy: false; | ||
}): DeepReadonly<CacheEntry<T>> | undefined; | ||
set<T>(key: Key, value: CacheEntry<T>): void; | ||
@@ -33,0 +46,0 @@ length(): number; |
{ | ||
"name": "@luvio/service-cache", | ||
"version": "5.26.0", | ||
"version": "5.27.0", | ||
"private": false, | ||
@@ -33,3 +33,3 @@ "description": "OneStore Cache Service definition", | ||
"dependencies": { | ||
"@luvio/utils": "5.26.0" | ||
"@luvio/utils": "5.27.0" | ||
}, | ||
@@ -36,0 +36,0 @@ "volta": { |
Sorry, the diff of this file is not supported yet
44577
605
+ Added@luvio/utils@5.27.0(transitive)
- Removed@luvio/utils@5.26.0(transitive)
Updated@luvio/utils@5.27.0