import Index from"./index.js";import{SearchOptions,DocumentSearchOptions}from"./type.js";export function searchCache(a,b,c){c||(b||"object"!=typeof a?"object"==typeof b&&(c=b,b=0):c=a),c&&(a=c.query||a,b=c.limit||b);let d=""+(b||0);if(c){const{context:a,suggest:b,offset:e,resolve:f,boost:g,resolution:h}=c;d+=(e||0)+!!a+!!b+(!1!==f)+(h||this.resolution)+(g||0)}a=(""+a).toLowerCase(),this.cache||(this.cache=new CacheClass);let e=this.cache.get(a+d);if(!e){const f=c&&c.cache;f&&(c.cache=!1),e=this.search(a,b,c),f&&(c.cache=f),this.cache.set(a+d,e)}return e}export default function CacheClass(a){this.limit=a&&!0!==a?a:1000,this.cache=new Map,this.last=""}CacheClass.prototype.set=function(a,b){this.cache.set(this.last=a,b),this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)},CacheClass.prototype.get=function(a){const b=this.cache.get(a);return b&&this.last!==a&&(this.cache.delete(a),this.cache.set(this.last=a,b)),b},CacheClass.prototype.remove=function(a){for(const b of this.cache){const c=b[0],d=b[1];d.includes(a)&&this.cache.delete(c)}},CacheClass.prototype.clear=function(){this.cache.clear(),this.last=""};