Files
klz-cables.com/.pnpm-store/v10/files/59/7f4ec05af6f614727f90f52f5f296ea6c73d075d5321955071dbc69e8efd40b0c333456f5a3f05ed6aeb24e77536c07d4502ffa8f36cbf1836ce20ea282427
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

38 lines
1.4 KiB
Plaintext

import { cache } from 'react';
// Module-scoped cache container that holds all cached, stable containers
// - these may hold the stable value, or a promise to the stable value
const globalCacheContainer = {};
/**
* Creates a selective cache function that provides more control over React's request-level caching behavior.
*
* @param namespace - A namespace to group related cached values
* @returns A function that manages cached values within the specified namespace
*/
export function selectiveCache(namespace) {
// Create a stable namespace container if it doesn't exist
if (!globalCacheContainer[namespace]) {
globalCacheContainer[namespace] = cache((...args) => ({
value: null
}));
}
/**
* Gets or creates a cached value for a specific key within the namespace
*
* @param key - The key to identify the cached value
* @param factory - A function that produces the value if not cached
* @returns The cached or newly created value
*/
const getCached = async (factory, ...cacheArgs) => {
const stableObjectFn = globalCacheContainer[namespace];
const stableObject = stableObjectFn(...cacheArgs);
if (stableObject?.value && 'then' in stableObject.value && typeof stableObject.value?.then === 'function') {
return await stableObject.value;
}
stableObject.value = factory();
return await stableObject.value;
};
return {
get: getCached
};
}
//# sourceMappingURL=selectiveCache.js.map