Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import { LRUCache } from "lru-cache";
|
||||
import { cachified as originalCachified, CacheEntry, CachifiedOptions, verboseReporter } from "@epic-web/cachified";
|
||||
|
||||
const lru = new LRUCache<string, CacheEntry>({ max: 1000 });
|
||||
|
||||
// replace this with redisCacheAdapter(redis) if you need to: https://github.com/epicweb-dev/cachified#adapter-for-redis
|
||||
export const cache = lru;
|
||||
|
||||
const CACHE_ENABLED = true;
|
||||
const CACHE_LOGGING_ENABLED = false;
|
||||
|
||||
export async function cachified<Value>(
|
||||
options: Omit<CachifiedOptions<Value>, "cache"> & {
|
||||
disabled?: boolean;
|
||||
}
|
||||
): Promise<Value> {
|
||||
if (!CACHE_ENABLED || options.disabled) {
|
||||
// @ts-ignore
|
||||
return options.getFreshValue(options);
|
||||
}
|
||||
return originalCachified({
|
||||
...options,
|
||||
cache,
|
||||
reporter: CACHE_LOGGING_ENABLED ? verboseReporter() : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
export function clearCacheKey(key: string): void {
|
||||
cache.delete(key);
|
||||
}
|
||||
|
||||
export function clearCacheKeyPrefix(prefix: string): void {
|
||||
for (const key of cache.keys()) {
|
||||
if (key.startsWith(prefix)) {
|
||||
cache.delete(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user