Thread‑safe TTL + LRU cache for in‑process caching with stats.
# Source: https://github.com/hoangsonww/Moodify-Emotion-Music-App | License: MIT | Copyright 2024-2026 Son Nguyen
# Provided via justclaw.it.com; keep this notice with the code.
"""In-process TTL + LRU cache used by the inference service.
We use this in two specific spots where caching is provably safe:
* Deezer search results (1h TTL) -- search output is stable on the
timescale of a single user session; the chart-rank-driven popularity
refreshes daily at most. Caching the search step does NOT cache the
per-request personalisation blend, which still runs every call.
* Text-emotion predictions (24h TTL) -- the BERT classifier is purely
deterministic on the normalised input string; ``bert-base-uncased``
lowercases anyway, so the cache key normalises the same way.
S
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key