Home > widget-integration > FilterStore > setCacheEntry
FilterStore.setCacheEntry() method
Stores a filter result in the cache with automatic LRU eviction.
Adds or updates a cache entry with the current timestamp. When the cache reaches its maximum size (50 entries), the oldest entry is automatically removed using LRU (Least Recently Used) eviction strategy.
Signature:
setCacheEntry(key: string, value: Omit<CacheEntry, "timestamp">): void;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
key |
string |
The unique cache key identifying this filter result |
|
value |
Omit<CacheEntry, "timestamp"> |
The cache entry data (timestamp is added automatically) |
Returns:
void
Remarks
The LRU eviction iterates through all cache entries to find the oldest one. For very large caches, consider overriding this method with a more efficient data structure like a linked list or using a library implementation.
Example 1
Basic usage:
filterStore.setCacheEntry('filter-v1-cat:shoes', {
data: { products: [...], total: 42 },
params: { category: 'shoes' }
});
Example 2
Extend to customize cache size per shop:
window.boostWidgetIntegration.extend('FilterStore', (FilterStore) => {
return class CustomFilterStore extends FilterStore {
setCacheEntry(key, value) {
const timestamp = new Date().getTime();
this.cache.value.set(key, { ...value, timestamp });
// Use larger cache for premium shops
const maxCacheSize = this.getMaxCacheSize();
if (this.cache.value.size >= maxCacheSize) {
// Custom eviction logic
}
}
getMaxCacheSize() {
return window.shopTier === 'premium' ? 100 : 50;
}
};
});