Skip to main content

Module retention

Module retention 

Source
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§

RetentionConfig
Retention policy configuration.
RetentionGarbageCollector
Garbage collector for expired memories based on retention policy.
RetentionGcResult
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.