import type { SearchCacheInterface } from '../types/index.js' import { stringifyArray } from '../utils/index.js' /** * @param {Record = {} ): SearchCacheInterface { let searchCache = cache return { getEntry: function (key: string): T | undefined { if (searchCache[key]) { try { return JSON.parse(searchCache[key]) } catch { return undefined } } return undefined }, formatKey: function (components: any[]) { return stringifyArray(components) }, setEntry: function (key: string, searchResponse: T) { searchCache[key] = JSON.stringify(searchResponse) }, clearCache: function () { searchCache = {} }, } }