Array of manga titles whose cache entries should be removed.
Object with cleared count, remaining cache size, and count of titles with no cache.
export function clearCacheForTitles(titles: string[]): {
clearedCount: number;
remainingCacheSize: number;
titlesWithNoCache: number;
} {
console.debug(
`[MangaSearchService] Clearing cache for ${titles.length} manga titles...`,
);
let clearedCount = 0;
let titlesWithNoCache = 0;
// Remove cache entries for each provided title
for (const title of titles) {
const cacheKey = generateCacheKey(title);
if (mangaCache[cacheKey]) {
delete mangaCache[cacheKey];
clearedCount++;
} else {
titlesWithNoCache++;
}
}
// Save updated cache to localStorage if entries were cleared
// Uses dynamic import to avoid circular dependency with persistence module
if (clearedCount > 0) {
import("./persistence").then(({ saveCache }) => saveCache());
}
const remainingCacheSize = Object.keys(mangaCache).length;
console.debug(
`[MangaSearchService] Cache cleared: ${clearedCount} entries removed, ${titlesWithNoCache} not found, ${remainingCacheSize} remaining`,
);
return {
clearedCount,
remainingCacheSize,
titlesWithNoCache,
};
}
Clears cache entries for specific manga titles and persists changes. Generates cache keys from titles and removes matching entries.