Rust

cache

Module

A cache of registrar answers per domain (prices, availability), on any key-value Store.

Contents

use utopia_domains::Cache;
Rust
pub struct Cache

Registrar answers cached per domain, under domain:<domain> keys (lower-cased) of a Store. Cloning shares the store.

Rust
use serde_json::json;
use utopia_domains::{Cache, MemoryStore};

let cache = Cache::new(MemoryStore::new());
tokio::runtime::Runtime::new()?.block_on(async {
    assert!(cache.save("example.com", &json!({"price": 12.99})).await);
    assert_eq!(cache.load("example.com", 3600).await, Some(json!({"price": 12.99})));
    assert!(cache.purge("example.com").await);
    assert_eq!(cache.load("example.com", 3600).await, None);
});
Also implements Debug.
use utopia_domains::MemoryStore;
Rust
pub struct MemoryStore

A store that keeps entries in this process, each with the second it was saved. Empty values, and the keys "" and "0", are not stored.

use utopia_domains::NoStore;
Rust
pub struct NoStore

A store that keeps nothing: every load misses, every save is refused, every purge succeeds.

use utopia_domains::Store;
Rust
pub trait Store: Send + Sync

Where a Cache keeps its entries: implement it over any key-value store (Redis, Memcached, a database). Keys arrive lower-cased.

MemoryStore keeps entries in the process; NoStore keeps nothing.

Implemented byMemoryStoreNoStore
Rust
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>

A boxed future, as Store returns them (the trait is object safe).