28 lines · 692 B · TypeScript
RawDownload
import type { SearchOptions, Source, TorrentResult } from "./types"; const TTL_MS = 5 * 60 * 1000; interface Entry {  at: number;  results: TorrentResult[];} const cache = new Map<string, Entry>(); function key(sourceId: string, query: string): string {  return `${sourceId}::${query.trim().toLowerCase()}`;} export async function cachedSearch(  source: Source,  query: string,  opts: SearchOptions = {},): Promise<TorrentResult[]> {  const k = key(source.id, query);  const hit = cache.get(k);  if (hit && Date.now() - hit.at < TTL_MS) return hit.results;   const results = await source.search(query, opts);  cache.set(k, { at: Date.now(), results });  return results;}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t