pub struct ExactMatchCache { /* private fields */ }Expand description
Exact-match Redis cache for ChatResponse values.
Implementations§
Source§impl ExactMatchCache
impl ExactMatchCache
Sourcepub fn disabled(namespace: &str) -> Self
pub fn disabled(namespace: &str) -> Self
Construct a disabled cache that never connects to Redis.
Sourcepub async fn new(redis_url: &str, namespace: &str) -> Self
pub async fn new(redis_url: &str, namespace: &str) -> Self
Connect to Redis at redis_url. On failure the cache is disabled and
all operations become no-ops.
Sourcepub fn from_connection_manager(
manager: ConnectionManager,
namespace: &str,
) -> Self
pub fn from_connection_manager( manager: ConnectionManager, namespace: &str, ) -> Self
Create an ExactMatchCache from an existing ConnectionManager. This allows sharing a single Redis connection across subsystems.
Sourcepub fn cache_key(&self, request: &ChatRequest) -> Option<String>
pub fn cache_key(&self, request: &ChatRequest) -> Option<String>
Compute the cache key for request.
Sourcepub async fn get(&self, request: &ChatRequest) -> Option<ChatResponse>
pub async fn get(&self, request: &ChatRequest) -> Option<ChatResponse>
Attempt to retrieve a cached ChatResponse for request.
Returns None on cache miss, Redis error, or deserialisation failure.
Sourcepub async fn set(&self, request: &ChatRequest, response: &ChatResponse)
pub async fn set(&self, request: &ChatRequest, response: &ChatResponse)
Store response in the cache under the key derived from request.
Silently ignores serialisation and Redis errors.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for ExactMatchCache
impl !UnwindSafe for ExactMatchCache
impl Forget for ExactMatchCache
impl Freeze for ExactMatchCache
impl Move for ExactMatchCache
impl Send for ExactMatchCache
impl Sync for ExactMatchCache
impl Unpin for ExactMatchCache
impl UnsafeUnpin for ExactMatchCache
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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> ⓘ
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 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> ⓘ
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