Skip to main content

Crate siderite_cache

Crate siderite_cache 

Source
Expand description

Cache backends and HTTP route caching for siderite applications.

MemoryCache is a process-local LRU with per-entry TTL. RedisCache (feature redis) wraps siderite_backends::redis::RedisStore. RouteCache is a tower layer for App::layer that caches GET/HEAD 200 responses.

use siderite_cache::{Cache, CacheExt, MemoryCache};
use std::time::Duration;

let cache = MemoryCache::new(128);
cache.set("greeting", b"hello".to_vec(), None).await.unwrap();
assert_eq!(
    cache.get("greeting").await.unwrap().as_deref(),
    Some(&b"hello"[..])
);
cache
    .set_json("n", &7u32, Some(Duration::from_secs(60)))
    .await
    .unwrap();
assert_eq!(cache.get_json::<u32>("n").await.unwrap(), Some(7));

Structs§

AdmitMarker
What Cache::admit_marker must decide.
MemoryCache
In-memory LRU cache with per-entry time-to-live.
MemoryCacheLimits
Hard byte-admission limits for process-local cache storage.
RedisCache
Redis-backed Cache.
RouteCache
Middleware that caches successful GET and HEAD responses.

Enums§

Admission
Outcome of Cache::admit_marker.
CacheError
Failure from a Cache operation.

Constants§

DEFAULT_GENERATION_TTL
Default lifetime of a target’s generation marker (one hour).
DEFAULT_MAX_BODY_BYTES
Largest body stored by default (1 MiB).
DEFAULT_MAX_NEW_TARGETS
Default admission budget: new markers per namespace per generation_ttl window.

Traits§

Cache
Byte-oriented cache with optional per-entry time-to-live.
CacheExt
JSON helpers implemented for every Cache.