• Clear the search cache entirely or for specific queries. Persists the cleared cache to storage and notifies main process.

    Parameters

    • OptionalsearchQuery: string

      Optional query to clear only matching entries; clears all if omitted.

    Returns void

    export function clearSearchCache(searchQuery?: string): void {
    if (searchQuery) {
    // Clear specific cache entries
    for (const key of Object.keys(searchCache)) {
    if (key.includes(searchQuery.toLowerCase())) {
    delete searchCache[key];
    }
    }
    console.info(`[AniListClient] 🗑️ Cleared search cache for: ${searchQuery}`);
    } else {
    // Clear all cache
    for (const key of Object.keys(searchCache)) {
    delete searchCache[key];
    }
    console.info("[AniListClient] 🗑️ Cleared all search cache");
    }

    // Update storage with the cleared cache immediately (critical operation)
    persistSearchCacheNow();

    // Also clear the cache in the main process
    globalThis.electronAPI.anilist
    .clearCache(searchQuery)
    .catch((error: Error) => {
    console.error(
    "[AniListClient] ❌ Failed to clear main process cache:",
    error,
    );
    });
    }