pub struct CachedResponse {
pub response: ChatResponse,
pub created_at: SystemTime,
pub ttl: Duration,
}Expand description
Cached response with metadata.
This struct wraps a response with creation time and TTL information for automatic expiration handling.
§Examples
use ultrafast_models_sdk::cache::CachedResponse;
use std::time::Duration;
let response = ChatResponse { /* ... */ };
let cached = CachedResponse::new(response, Duration::from_secs(3600));
if !cached.is_expired() {
println!("Response is still valid");
}Fields§
§response: ChatResponseThe cached response data
created_at: SystemTimeWhen this entry was created
ttl: DurationHow long this entry should be considered valid
Implementations§
Source§impl CachedResponse
impl CachedResponse
Sourcepub fn new(response: ChatResponse, ttl: Duration) -> Self
pub fn new(response: ChatResponse, ttl: Duration) -> Self
Create a new cached response.
§Arguments
response- The response to cachettl- Time-to-live for the cached response
§Examples
use ultrafast_models_sdk::cache::CachedResponse;
use std::time::Duration;
let response = ChatResponse { /* ... */ };
let cached = CachedResponse::new(response, Duration::from_secs(3600));Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check if this cached response has expired.
Returns true if the response has exceeded its TTL, false otherwise.
§Examples
use ultrafast_models_sdk::cache::CachedResponse;
use std::time::Duration;
let cached = CachedResponse::new(response, Duration::from_secs(3600));
if cached.is_expired() {
println!("Response has expired");
} else {
println!("Response is still valid");
}Trait Implementations§
Source§impl Clone for CachedResponse
impl Clone for CachedResponse
Source§fn clone(&self) -> CachedResponse
fn clone(&self) -> CachedResponse
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CachedResponse
impl Debug for CachedResponse
Source§impl<'de> Deserialize<'de> for CachedResponse
impl<'de> Deserialize<'de> for CachedResponse
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for CachedResponse
impl RefUnwindSafe for CachedResponse
impl Send for CachedResponse
impl Sync for CachedResponse
impl Unpin for CachedResponse
impl UnwindSafe for CachedResponse
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