pub struct PageCache { /* private fields */ }Expand description
Redis-backed cache for paginated lists.
Implementations§
Source§impl PageCache
impl PageCache
Sourcepub fn offline() -> Self
pub fn offline() -> Self
In-memory placeholder (no Redis) for offline adapters/tests: every
operation is a no-op. Real adapters should use connect().
Sourcepub async fn connect(config: &BotConfig) -> Result<Self>
pub async fn connect(config: &BotConfig) -> Result<Self>
Connect to Redis (same URL as FicHub).
Sourcepub async fn store(
&self,
title: &str,
entries: Vec<PageEntry>,
) -> Result<String>
pub async fn store( &self, title: &str, entries: Vec<PageEntry>, ) -> Result<String>
Store a new list, returning its session id.
Sourcepub async fn store_for_user(
&self,
user_id: u64,
title: &str,
entries: Vec<PageEntry>,
) -> Result<String>
pub async fn store_for_user( &self, user_id: u64, title: &str, entries: Vec<PageEntry>, ) -> Result<String>
Store a new list for a user, remembering it as their “latest” session
(so !next/!prev/!page X know which list to paginate).
Sourcepub async fn latest_for_user(&self, user_id: u64) -> Result<Option<String>>
pub async fn latest_for_user(&self, user_id: u64) -> Result<Option<String>>
The user’s most recent list session id, if any.
Sourcepub async fn current_page(&self, session_id: &str) -> Result<Option<usize>>
pub async fn current_page(&self, session_id: &str) -> Result<Option<usize>>
Current page for a session (defaults to 1 when unset).
Sourcepub async fn set_current_page(
&self,
session_id: &str,
page: usize,
) -> Result<()>
pub async fn set_current_page( &self, session_id: &str, page: usize, ) -> Result<()>
Record the current page for a session.
Sourcepub async fn fetch(&self, session_id: &str) -> Result<Option<PageList>>
pub async fn fetch(&self, session_id: &str) -> Result<Option<PageList>>
Fetch a stored list by session id.
Sourcepub async fn delete(&self, session_id: &str) -> Result<()>
pub async fn delete(&self, session_id: &str) -> Result<()>
Delete a stored list (call after a session ends).
Sourcepub async fn log_search(&self, entry: &SearchLogEntry)
pub async fn log_search(&self, entry: &SearchLogEntry)
Append a search-log entry to today’s Redis list, trimming to the last
SEARCH_LOG_CAP entries and giving the key a 7-day TTL.
Logging is best-effort: a Redis failure must never break the search
command, so the caller ignores the error. Keys look like
archivist:searchlog:2026-08-15.
Sourcepub async fn cached_response(&self, kind: &str, query: &str) -> Option<Value>
pub async fn cached_response(&self, kind: &str, query: &str) -> Option<Value>
Look up a cached response value by kind + raw query.
kind selects the key prefix + TTL: "ask" (archivist:askcache:<h>)
or "search" (archivist:searchcache:<h>). Only the raw JSON bytes
are cached; the caller deserializes into the typed response so this
method stays generic. Returns Ok(None) on miss or Redis failure
(best-effort — a broken cache must never break the command).
Sourcepub async fn cache_response(&self, kind: &str, query: &str, value: &Value)
pub async fn cache_response(&self, kind: &str, query: &str, value: &Value)
Store a response value in the cache (best-effort, like log_search).
kind selects the TTL: ask entries live longer (LLM cost is the
dominant expense); search entries get a short TTL so results do not go
stale as the archive grows.
Sourcepub async fn cached_raw(&self, key: &str) -> Option<Value>
pub async fn cached_raw(&self, key: &str) -> Option<Value>
Look up a raw cached value by an EXPLICIT key (e.g. the intent cache,
which uses its own TTL). Returns Ok(None) on miss or Redis failure.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for PageCache
impl !UnwindSafe for PageCache
impl Freeze for PageCache
impl Send for PageCache
impl Sync for PageCache
impl Unpin for PageCache
impl UnsafeUnpin for PageCache
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more