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