Skip to content

Bound nostr event cache TTL and size#22

Open
alltheseas wants to merge 3 commits into
damus-io:masterfrom
alltheseas:cache-prune-cap
Open

Bound nostr event cache TTL and size#22
alltheseas wants to merge 3 commits into
damus-io:masterfrom
alltheseas:cache-prune-cap

Conversation

@alltheseas
Copy link
Copy Markdown

@alltheseas alltheseas commented Dec 11, 2025

addresses

#14

Summary

  • set cache TTL default to 30m, configurable via env
  • add hard cap on cache entries with oldest-first eviction and eager pruning
  • add tests covering pruning and cap eviction

Testing

  • cargo test

Summary by CodeRabbit

  • New Features

    • Added configurable cache entry limit (default: 10,000) to optimize memory usage and system performance. This can be customized via environment configuration.
  • Chores

    • Reduced default event cache retention period from 1 hour to 30 minutes for improved data freshness and reduced memory overhead.

✏️ Tip: You can customize this high-level summary in your review settings.

Signed-off-by: alltheseas <64376233+alltheseas@users.noreply.github.com>
Closes damus-io#14
Signed-off-by: alltheseas <64376233+alltheseas@users.noreply.github.com>
Signed-off-by: alltheseas <64376233+alltheseas@users.noreply.github.com>
@jb55
Copy link
Copy Markdown
Contributor

jb55 commented Dec 11, 2025

whats this for?

@jb55
Copy link
Copy Markdown
Contributor

jb55 commented Dec 11, 2025

@alltheseas
Copy link
Copy Markdown
Author

cargo test passed, but needs to be tested in production.

the cache clearing variables can be adjusted accordingly

@alltheseas
Copy link
Copy Markdown
Author

@coderabbitai review please

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 16, 2026

@alltheseas, I'll review the changes in this PR for you.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 16, 2026

📝 Walkthrough

Walkthrough

This pull request adds cache entry count limiting functionality to the Nostr event cache system. A new configuration parameter DEFAULT_NOSTR_EVENT_CACHE_MAX_ENTRIES (10,000) is introduced, threaded through environment initialization and the notification manager stack, and integrated into the Cache with supporting eviction logic. The default cache age is also reduced from 1 hour to 30 minutes.

Changes

Cohort / File(s) Summary
Configuration & Environment
src/notepush_env.rs
Adds DEFAULT_NOSTR_EVENT_CACHE_MAX_ENTRIES constant (10,000), new field nostr_event_cache_max_entries to NotePushEnv, reduces DEFAULT_NOSTR_EVENT_CACHE_MAX_AGE from 1 hour to 30 minutes, reads NOSTR_EVENT_CACHE_MAX_ENTRIES environment variable.
Initialization & Manager
src/main.rs, src/notification_manager/mod.rs
Threads nostr_event_cache_max_entries from environment through NotificationManager::new() and into NostrNetworkHelper::new().
Cache Implementation
src/notification_manager/nostr_event_cache.rs, src/notification_manager/nostr_network_helper.rs
Adds max_entries field to Cache, introduces prune_expired_entries(), remove_expired_from(), and enforce_cap() methods for expiration and eviction management. Cache::new() constructor updated to accept both max_age and max_entries parameters. Eviction logic wired into add/get paths.
Utilities
src/utils/time_delta.rs
Adds #[allow(dead_code)] attribute to suppress warnings on TimeDelta::subtracting() function.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~28 minutes

Poem

🐰 A cache with limits, now bounded and lean,
Ten thousand entries—no overflow scene!
With pruning and eviction in every command,
Our memory stays tidy across the land! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 48.15% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'Bound nostr event cache TTL and size' directly and concisely summarizes the main changes: adding TTL (time-to-live) bounds and size limits to the nostr event cache.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@alltheseas
Copy link
Copy Markdown
Author

@coderabbitai review please

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 22, 2026

@alltheseas, I'll review the changes in this PR for you.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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