pub struct ResponseCache { /* private fields */ }Expand description
Cache successful GET responses in a KvStore.
Implementations§
Source§impl ResponseCache
impl ResponseCache
pub fn new(store: Arc<dyn KvStore>) -> Self
Sourcepub fn from_app(app: &App) -> Self
pub fn from_app(app: &App) -> Self
Use installed sova_store::AppStore (rcache namespace).
pub fn ttl(self, ttl: Duration) -> Self
pub fn max_body(self, bytes: usize) -> Self
pub fn vary(self, headers: &[&str]) -> Self
Sourcepub fn cache_private(self, yes: bool) -> Self
pub fn cache_private(self, yes: bool) -> Self
Allow caching requests that carry Authorization / Cookie.
pub fn prefix(self, prefix: impl Into<String>) -> Self
Sourcepub async fn invalidate_prefix(&self, path_prefix: &str) -> u64
pub async fn invalidate_prefix(&self, path_prefix: &str) -> u64
Invalidate keys under path_prefix (same as ResponseCacheHandle::invalidate_prefix).
Typical pattern with sova_core::EventBus:
ⓘ
let handle = app.try_state::<ResponseCacheHandle>().unwrap();
bus.listen::<NoteCreated, _>(move |_| {
let h = handle.clone();
tokio::spawn(async move { h.invalidate_prefix("/api/notes").await; });
});pub fn middleware(self) -> MwEntry
Trait Implementations§
Source§impl Clone for ResponseCache
impl Clone for ResponseCache
Source§fn clone(&self) -> ResponseCache
fn clone(&self) -> ResponseCache
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Plugin for ResponseCache
impl Plugin for ResponseCache
Source§fn id(&self) -> &'static str
fn id(&self) -> &'static str
Stable plugin identifier used for dependency checks and
crate::App::has_plugin. Read moreSource§fn meta(&self) -> PluginMeta
fn meta(&self) -> PluginMeta
Display name, description, and declared
PluginMeta::sdk version.Auto Trait Implementations§
impl !RefUnwindSafe for ResponseCache
impl !UnwindSafe for ResponseCache
impl Freeze for ResponseCache
impl Send for ResponseCache
impl Sync for ResponseCache
impl Unpin for ResponseCache
impl UnsafeUnpin for ResponseCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more