Skip to main content

PageCache

Struct PageCache 

Source
pub struct PageCache { /* private fields */ }
Expand description

Redis-backed cache for paginated lists.

Implementations§

Source§

impl PageCache

Source

pub fn offline() -> Self

In-memory placeholder (no Redis) for offline adapters/tests: every operation is a no-op. Real adapters should use connect().

Source

pub async fn connect(config: &BotConfig) -> Result<Self>

Connect to Redis (same URL as FicHub).

Source

pub async fn store( &self, title: &str, entries: Vec<PageEntry>, ) -> Result<String>

Store a new list, returning its session id.

Source

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).

Source

pub async fn latest_for_user(&self, user_id: u64) -> Result<Option<String>>

The user’s most recent list session id, if any.

Source

pub async fn current_page(&self, session_id: &str) -> Result<Option<usize>>

Current page for a session (defaults to 1 when unset).

Source

pub async fn set_current_page( &self, session_id: &str, page: usize, ) -> Result<()>

Record the current page for a session.

Source

pub async fn fetch(&self, session_id: &str) -> Result<Option<PageList>>

Fetch a stored list by session id.

Source

pub async fn delete(&self, session_id: &str) -> Result<()>

Delete a stored list (call after a session ends).

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.

Source

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).

Source

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.

Source

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.

Source

pub async fn cache_raw(&self, key: &str, ttl_secs: u64, value: &Value)

Store a raw JSON value under an EXPLICIT key + TTL (best-effort).

Trait Implementations§

Source§

impl Clone for PageCache

Source§

fn clone(&self) -> PageCache

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more