Skip to main content

💾 Caching & Local Storage

leetrs minimizes network latency by maintaining a local disk cache for problem metadata and credentials.


📁 Data Storage Layout

ResourcePath LocationDescription
Config~/.config/leetrs/config.tomlUser preferences (editor, language, show_description)
Credentials~/.config/leetrs/credentials.jsonActive session tokens (csrftoken, session_cookie)
Problem Cache~/.local/share/leetrs/data.jsonCached problem summaries, difficulties, acceptance, and topic tags

⚡ Cache Service Mechanics (src/cache.rs)

  1. First Run / Cache Miss: When leetrs tui or list_problems() is called for the first time, CacheService queries LeetCode GraphQL API to fetch the full problem list and writes it to data.json.
  2. Cache Hit: On subsequent launches, data.json is deserialized instantly into memory, reducing boot time to under 10 milliseconds.
  3. Cache Invalidation: To force a fresh problem synchronization:
    rm -rf ~/.local/share/leetrs/data.json