doido-cache 0.0.6

Named cache stores, TTL — memory/Redis/Memcached backends in ActiveSupport::Cache fashion for Doido.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use doido_cache::{CacheRegistry, MemoryStore};
use serde_json::json;
use std::sync::Arc;

#[tokio::test]
async fn test_registry_add_and_retrieve() {
    let mut reg = CacheRegistry::new();
    reg.add("default", Arc::new(MemoryStore::new()));
    let store = reg.store("default").unwrap();
    store.set("k", json!(42), None).await.unwrap();
    assert_eq!(store.get("k").await.unwrap(), Some(json!(42)));
}

#[test]
fn test_registry_missing_store_returns_none() {
    let reg = CacheRegistry::new();
    assert!(reg.store("nonexistent").is_none());
}