Skip to content

Add persistent AI cache for TLDRs and chat with 7-day expiry - #25

Merged
brianlovin merged 2 commits into
mainfrom
claude/cache-post-summaries-JgBn7
Jan 26, 2026
Merged

Add persistent AI cache for TLDRs and chat with 7-day expiry#25
brianlovin merged 2 commits into
mainfrom
claude/cache-post-summaries-JgBn7

Conversation

@brianlovin

Copy link
Copy Markdown
Owner

Summary

Implements persistent caching for AI-generated content (TLDRs and chat sessions) that survives application restarts. These caches are stored in the user's home directory with a 7-day expiration policy, while the existing session cache remains in the temp directory.

Key Changes

  • Persistent cache storage: TLDR and chat caches now stored in ~/.cache/hn-cli/ instead of temp directory, allowing them to persist across reboots
  • 7-day expiration: Both TLDR and chat caches expire after 7 days, with automatic cleanup of stale entries on load/save
  • Cache merging: Session cache and persistent cache are intelligently merged during initialization, with persistent cache taking precedence for existing entries
  • Immediate persistence: TLDR cache is saved immediately after generation completes, not just on app exit
  • Graceful degradation: All cache operations fail silently to prevent crashes if filesystem operations fail

Implementation Details

  • Added loadTLDRCache() and saveTLDRCache() functions to manage TLDR persistence
  • Added loadChatCache() and saveChatCache() functions to manage chat session persistence
  • New cache interfaces: CachedTLDR, PersistentChatSession, TLDRCache, and ChatCache with timestamp tracking
  • Cache entries are keyed by story ID as strings for JSON serialization
  • Existing timestamps are preserved when re-saving caches to maintain accurate expiration times
  • Expired entries are filtered out during load and save operations

claude and others added 2 commits January 26, 2026 07:45
- Store TLDR summaries in ~/.cache/hn-cli/tldr-cache.json with 7-day expiry
- Store chat sessions in ~/.cache/hn-cli/chat-cache.json with 7-day expiry
- Both caches survive app restarts and system reboots
- Expired entries are automatically cleaned up on load
- Users can regenerate TLDRs by pressing 't' again
- Add setPersistentCachePaths() for test path injection
- Add comprehensive tests for TLDR and chat cache functions
- Improve merge behavior comment explaining precedence logic
- Export AI_CACHE_TTL_MS constant for test verification

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@brianlovin
brianlovin force-pushed the claude/cache-post-summaries-JgBn7 branch from 116e4a5 to 8da929f Compare January 26, 2026 15:45
@brianlovin
brianlovin merged commit dc860c7 into main Jan 26, 2026
1 check passed
@brianlovin
brianlovin deleted the claude/cache-post-summaries-JgBn7 branch January 26, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants