Expand description
In-memory capture buffer for web content
This module provides a thread-safe, bounded buffer for storing captured web content with automatic cleanup of stale entries and FIFO eviction when capacity is reached.
§Features
- Bounded size: Maximum 1000 captures by default
- Time-based expiry: Entries expire after 1 hour by default
- Thread-safe: Uses
RwLockfor concurrent read access - Memory efficient: Optional LZ4 compression for content
- Background cleanup: Automatic removal of expired entries
§Example
use reasonkit_web::buffer::{CaptureBuffer, CaptureRecord};
use std::time::Duration;
use std::sync::Arc;
#[tokio::main]
async fn main() {
// Create buffer with defaults
let buffer = Arc::new(CaptureBuffer::new());
// Or with custom settings
let buffer = Arc::new(CaptureBuffer::builder()
.max_size(500)
.max_age(Duration::from_secs(1800)) // 30 minutes
.enable_compression(true)
.build());
// Start background cleanup
buffer.start_cleanup_task();
// Add a capture
let record = CaptureRecord::new(
"https://example.com".to_string(),
"<html>...</html>".to_string(),
"Extracted content...".to_string(),
1234,
);
buffer.push(record).await;
// Retrieve captures
let recent = buffer.get_recent(10).await;
println!("Recent captures: {}", recent.len());
}Structs§
- Buffer
Config - Configuration for the capture buffer
- Buffer
Stats - Statistics about buffer usage
- Capture
Buffer - Thread-safe in-memory buffer for captured web content
- Capture
Buffer Builder - Builder for CaptureBuffer
- Capture
Record - A single captured page record
Constants§
- DEFAULT_
CLEANUP_ INTERVAL_ SECS - Default cleanup interval (5 minutes)
- DEFAULT_
MAX_ AGE_ SECS - Default maximum age of captures (1 hour)
- DEFAULT_
MAX_ SIZE - Default maximum number of captures in the buffer
Functions§
- shared_
buffer - Create a new shared capture buffer
- shared_
buffer_ with_ config - Create a new shared capture buffer with custom config
Type Aliases§
- Shared
Capture Buffer - Wrapper for using CaptureBuffer in Arc contexts