Skip to main content

Module cache

Module cache 

Source
Expand description

Client-side query result cache for the AmateRS Rust SDK

Provides an LRU (Least Recently Used) cache for query results, reducing round-trips to the server for frequently accessed data. The cache is thread-safe and supports TTL-based expiration, collection-level invalidation, and configurable size limits.

§Example

use amaters_sdk_rust::cache::{QueryCache, QueryCacheConfig, InvalidationPolicy};
use std::time::Duration;

let config = QueryCacheConfig::default()
    .with_max_entries(500)
    .with_ttl(Duration::from_secs(120))
    .with_max_value_size(512 * 1024);

let cache = QueryCache::new(config);

// Put and get
cache.put(b"key1", vec![1, 2, 3]);
if let Some(data) = cache.get(b"key1") {
    assert_eq!(data, vec![1, 2, 3]);
}

Structs§

CacheStats
Statistics about cache usage.
QueryCache
Thread-safe LRU cache for query results.
QueryCacheConfig
Configuration for the query cache.

Enums§

InvalidationPolicy
Policy for cache invalidation when a write operation occurs.