UNPKG

@mcabreradev/filter

Version:

A powerful, SQL-like array filtering library for TypeScript and JavaScript with advanced pattern matching, MongoDB-style operators, deep object comparison, and zero dependencies

20 lines (19 loc) 508 B
import { LRUCache } from '../memoization/memoization'; export class FilterCache { cache = new WeakMap(); get(array, key) { return this.cache.get(array)?.get(key); } set(array, key, result) { if (!this.cache.has(array)) { this.cache.set(array, new LRUCache(100)); } const arrayCache = this.cache.get(array); if (arrayCache) { arrayCache.set(key, result); } } clear() { this.cache = new WeakMap(); } }