diff --git a/packages/core/src/browser-storage/config.ts b/packages/core/src/browser-storage/config.ts index 337840a..975ffdf 100644 --- a/packages/core/src/browser-storage/config.ts +++ b/packages/core/src/browser-storage/config.ts @@ -9,3 +9,6 @@ export const browserCacheVersionKey = browserCachePrefix + '-version'; // Cache expiration export const browserStorageHour = 3600000; export const browserStorageCacheExpiration = 168; // In hours + +// Maximum number of stored items +export const browserStorageLimit = 50; diff --git a/packages/core/src/browser-storage/store.ts b/packages/core/src/browser-storage/store.ts index 6fe188e..a41f66f 100644 --- a/packages/core/src/browser-storage/store.ts +++ b/packages/core/src/browser-storage/store.ts @@ -1,6 +1,10 @@ import type { IconifyJSON } from '@iconify/types'; import type { IconStorage } from '../storage/storage'; -import { browserCachePrefix, browserStorageHour } from './config'; +import { + browserCachePrefix, + browserStorageHour, + browserStorageLimit, +} from './config'; import { getBrowserStorageItemsCount, setBrowserStorageItemsCount, @@ -13,7 +17,7 @@ import { import { iterateBrowserStorage } from './foreach'; import { getBrowserStorage } from './global'; import { initBrowserStorage } from './index'; -import { setStoredItem } from './item'; +import { getStoredItem, setStoredItem } from './item'; import type { BrowserStorageInstance, BrowserStorageItem, @@ -81,9 +85,12 @@ export function storeInBrowserStorage(storage: IconStorage, data: IconifyJSON) { // Remove item from set set.delete((index = Array.from(set).shift() as number)); } else { - // Create new index + // Append new item, unless exceeded storage limit index = getBrowserStorageItemsCount(func); - if (!setBrowserStorageItemsCount(func, index + 1)) { + if ( + index >= browserStorageLimit || + !setBrowserStorageItemsCount(func, index + 1) + ) { return; } }