Expand description
Retention policy garbage collector implementation.
Identifies and tombstones memories that have exceeded their retention period.
§Configuration
Retention can be configured via:
- Environment variable:
SUBCOG_RETENTION_DAYS(default: 365) - Config file:
[gc] retention_days = 365 - Per-namespace overrides:
[gc.retention] decisions = 730
§Example
ⓘ
use subcog::gc::{RetentionConfig, RetentionGarbageCollector};
use subcog::storage::index::SqliteBackend;
use std::sync::Arc;
// Load retention config from environment
let config = RetentionConfig::from_env();
assert_eq!(config.default_days, 365);
// Create retention GC with index backend
let backend = Arc::new(SqliteBackend::new("memories.db")?);
let gc = RetentionGarbageCollector::new(backend, config);
// Dry run to see what would be cleaned up
let result = gc.gc_expired_memories(true)?;
println!("Would tombstone {} expired memories", result.memories_tombstoned);
// Actually perform the cleanup
let result = gc.gc_expired_memories(false)?;
println!("Tombstoned {} memories", result.memories_tombstoned);Structs§
- Retention
Config - Retention policy configuration.
- Retention
Garbage Collector - Garbage collector for expired memories based on retention policy.
- Retention
GcResult - Result of a retention garbage collection operation.
Constants§
- DEFAULT_
RETENTION_ DAYS - Default retention period in days (1 year).
- RETENTION_
DAYS_ ENV - Environment variable for default retention period in days.
Functions§
- duration_
to_ 🔒millis - Safely converts Duration to milliseconds as u64, capping at
u64::MAX. - retention_
days - Returns the configured retention period in days.
- u64_
to_ 🔒f64 - Converts u64 to f64 for metrics, capping at
u32::MAX. - usize_
to_ 🔒f64 - Converts usize to f64 for metrics, capping at
u32::MAX.