Files
klz-cables.com/.pnpm-store/v10/files/99/9f643df04cda3dab0212101abce466e8e77d9579ed997dad545f7d2b6fbac83261e1801696cb31a712459467334e406ebdb1da6b76b0102ca267285787b3f0
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

65 lines
1.6 KiB
Plaintext

/** A simple Least Recently Used map */
class LRUMap {
constructor( _maxSize) {this._maxSize = _maxSize;
this._cache = new Map();
}
/** Get the current size of the cache */
get size() {
return this._cache.size;
}
/** Get an entry or undefined if it was not in the cache. Re-inserts to update the recently used order */
get(key) {
const value = this._cache.get(key);
if (value === undefined) {
return undefined;
}
// Remove and re-insert to update the order
this._cache.delete(key);
this._cache.set(key, value);
return value;
}
/** Insert an entry and evict an older entry if we've reached maxSize */
set(key, value) {
if (this._cache.size >= this._maxSize) {
// keys() returns an iterator in insertion order so keys().next() gives us the oldest key
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const nextKey = this._cache.keys().next().value;
this._cache.delete(nextKey);
}
this._cache.set(key, value);
}
/** Remove an entry and return the entry if it was in the cache */
remove(key) {
const value = this._cache.get(key);
if (value) {
this._cache.delete(key);
}
return value;
}
/** Clear all entries */
clear() {
this._cache.clear();
}
/** Get all the keys */
keys() {
return Array.from(this._cache.keys());
}
/** Get all the values */
values() {
const values = [];
this._cache.forEach(value => values.push(value));
return values;
}
}
export { LRUMap };
//# sourceMappingURL=lru.js.map