Download src/utils/investigationCache.js from NKessler/Horizon: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/NKessler/Horizon/resolve/main/src/utils/investigationCache.js
- Command line
-
hf download hf://NKessler/Horizon/src/utils/investigationCache.js
-
curl -L -o investigationCache.js https://huggingface.co/NKessler/Horizon/resolve/main/src/utils/investigationCache.js
1.49 kB
| /** In-memory cache for route remounts; keys = topic + timeframe (+ iso for article lists). FIFO cap per map. */ | |
| const MAX_ENTRIES = 16; | |
| const mapDivergence = new Map(); | |
| const mapArticles = new Map(); | |
| const timelinePayload = new Map(); | |
| function keyTopicTf(topic, newsTimeframe) { | |
| return `${topic.trim()}\u0000${newsTimeframe}`; | |
| } | |
| function keyArticles(topic, newsTimeframe, iso) { | |
| return `${keyTopicTf(topic, newsTimeframe)}\u0000${iso ?? "all"}`; | |
| } | |
| function setBounded(map, key, value) { | |
| if (map.has(key)) { | |
| map.delete(key); | |
| } else if (map.size >= MAX_ENTRIES) { | |
| const oldest = map.keys().next().value; | |
| map.delete(oldest); | |
| } | |
| map.set(key, value); | |
| } | |
| export function getCachedMapDivergence(topic, newsTimeframe) { | |
| return mapDivergence.get(keyTopicTf(topic, newsTimeframe)); | |
| } | |
| export function setCachedMapDivergence(topic, newsTimeframe, data) { | |
| setBounded(mapDivergence, keyTopicTf(topic, newsTimeframe), data); | |
| } | |
| export function getCachedMapArticles(topic, newsTimeframe, iso) { | |
| return mapArticles.get(keyArticles(topic, newsTimeframe, iso)); | |
| } | |
| export function setCachedMapArticles(topic, newsTimeframe, iso, data) { | |
| setBounded(mapArticles, keyArticles(topic, newsTimeframe, iso), data); | |
| } | |
| export function getCachedTimeline(topic, newsTimeframe) { | |
| return timelinePayload.get(keyTopicTf(topic, newsTimeframe)); | |
| } | |
| export function setCachedTimeline(topic, newsTimeframe, data) { | |
| setBounded(timelinePayload, keyTopicTf(topic, newsTimeframe), data); | |
| } | |