Trait hitbox::response::CacheableResponse [−][src]
pub trait CacheableResponse where
Self: Sized,
Self::Cached: Serialize, { type Cached; fn cache_policy(&self) -> CachePolicy<&Self::Cached, ()>; fn into_cache_policy(self) -> CachePolicy<Self::Cached, Self>; fn from_cached(cached: Self::Cached) -> Self; }
Expand description
Thit is one of the basic trait which determines should data store in cache backend or not.
For primitive types and for user-defined types (with derive macro) cache_policy returns CachePolicy::Cached variant.
For Result<T, E>
cache_policy method return CachePolicy::Cacheable(T)
only for data included into
Ok(T)
variant.
Option<T>
is the same with Result: for Some(T)
returns CachedPolicy::Cacheable(T)
. None
are
NonCacheable
by default.
User defined types:
If you want decribe custom caching rules for your own types (for example Enum) you should
implement CacheableResponse
for that type:
use hitbox::{CacheableResponse, CachePolicy}; enum HttpResponse { Ok(String), Unauthorized(i32), } impl CacheableResponse for HttpResponse { type Cached = String; fn cache_policy(&self) -> CachePolicy<&Self::Cached, ()> { match self { HttpResponse::Ok(body) => CachePolicy::Cacheable(body), _ => CachePolicy::NonCacheable(()), } } fn into_cache_policy(self) -> CachePolicy<Self::Cached, Self> { match self { HttpResponse::Ok(body) => CachePolicy::Cacheable(body), _ => CachePolicy::NonCacheable(self), } } fn from_cached(cached: Self::Cached) -> Self { HttpResponse::Ok(cached) } }
In that case only HttpResponse::Ok
variant will be saved into the cache backend.
And all String
s from the cache backend will be treated as HttpReponse::Ok(String)
variant.
Associated Types
Required methods
fn cache_policy(&self) -> CachePolicy<&Self::Cached, ()>
[src]
fn cache_policy(&self) -> CachePolicy<&Self::Cached, ()>
[src]Returns cache policy for current type with borrowed data.
fn into_cache_policy(self) -> CachePolicy<Self::Cached, Self>
[src]
fn into_cache_policy(self) -> CachePolicy<Self::Cached, Self>
[src]Returns cache policy for current type with owned data.
fn from_cached(cached: Self::Cached) -> Self
[src]
fn from_cached(cached: Self::Cached) -> Self
[src]Describes how previously cached data will be transformed into the original type.
Implementations on Foreign Types
impl<I, E> CacheableResponse for Result<I, E> where
I: Serialize + DeserializeOwned,
[src]
impl<I, E> CacheableResponse for Result<I, E> where
I: Serialize + DeserializeOwned,
[src]Implementation CacheableResponse
for Result
type.
We store to cache only Ok
variant.
type Cached = I
fn into_cache_policy(self) -> CachePolicy<Self::Cached, Self>
[src]
fn from_cached(cached: Self::Cached) -> Self
[src]
fn cache_policy(&self) -> CachePolicy<&Self::Cached, ()>
[src]
impl<I> CacheableResponse for Option<I> where
I: Serialize + DeserializeOwned,
[src]
impl<I> CacheableResponse for Option<I> where
I: Serialize + DeserializeOwned,
[src]Implementation CacheableResponse
for Option
type.
We store to cache only Some
variant.
type Cached = I
fn into_cache_policy(self) -> CachePolicy<Self::Cached, Self>
[src]
fn from_cached(cached: Self::Cached) -> Self
[src]
fn cache_policy(&self) -> CachePolicy<&Self::Cached, ()>
[src]
impl CacheableResponse for ()
[src]
impl CacheableResponse for ()
[src]type Cached = ()
fn into_cache_policy(self) -> CachePolicy<Self::Cached, Self>
[src]
fn from_cached(cached: Self::Cached) -> Self
[src]
fn cache_policy(&self) -> CachePolicy<&Self::Cached, ()>
[src]
impl CacheableResponse for u8
[src]
impl CacheableResponse for u8
[src]type Cached = u8
fn into_cache_policy(self) -> CachePolicy<Self::Cached, Self>
[src]
fn from_cached(cached: Self::Cached) -> Self
[src]
fn cache_policy(&self) -> CachePolicy<&Self::Cached, ()>
[src]
impl CacheableResponse for u16
[src]
impl CacheableResponse for u16
[src]type Cached = u16
fn into_cache_policy(self) -> CachePolicy<Self::Cached, Self>
[src]
fn from_cached(cached: Self::Cached) -> Self
[src]
fn cache_policy(&self) -> CachePolicy<&Self::Cached, ()>
[src]
impl CacheableResponse for u32
[src]
impl CacheableResponse for u32
[src]type Cached = u32
fn into_cache_policy(self) -> CachePolicy<Self::Cached, Self>
[src]
fn from_cached(cached: Self::Cached) -> Self
[src]
fn cache_policy(&self) -> CachePolicy<&Self::Cached, ()>
[src]
impl CacheableResponse for u64
[src]
impl CacheableResponse for u64
[src]type Cached = u64
fn into_cache_policy(self) -> CachePolicy<Self::Cached, Self>
[src]
fn from_cached(cached: Self::Cached) -> Self
[src]
fn cache_policy(&self) -> CachePolicy<&Self::Cached, ()>
[src]
impl CacheableResponse for usize
[src]
impl CacheableResponse for usize
[src]type Cached = usize
fn into_cache_policy(self) -> CachePolicy<Self::Cached, Self>
[src]
fn from_cached(cached: Self::Cached) -> Self
[src]
fn cache_policy(&self) -> CachePolicy<&Self::Cached, ()>
[src]
impl CacheableResponse for i8
[src]
impl CacheableResponse for i8
[src]type Cached = i8
fn into_cache_policy(self) -> CachePolicy<Self::Cached, Self>
[src]
fn from_cached(cached: Self::Cached) -> Self
[src]
fn cache_policy(&self) -> CachePolicy<&Self::Cached, ()>
[src]
impl CacheableResponse for i16
[src]
impl CacheableResponse for i16
[src]type Cached = i16
fn into_cache_policy(self) -> CachePolicy<Self::Cached, Self>
[src]
fn from_cached(cached: Self::Cached) -> Self
[src]
fn cache_policy(&self) -> CachePolicy<&Self::Cached, ()>
[src]
impl CacheableResponse for i32
[src]
impl CacheableResponse for i32
[src]type Cached = i32
fn into_cache_policy(self) -> CachePolicy<Self::Cached, Self>
[src]
fn from_cached(cached: Self::Cached) -> Self
[src]
fn cache_policy(&self) -> CachePolicy<&Self::Cached, ()>
[src]
impl CacheableResponse for i64
[src]
impl CacheableResponse for i64
[src]type Cached = i64
fn into_cache_policy(self) -> CachePolicy<Self::Cached, Self>
[src]
fn from_cached(cached: Self::Cached) -> Self
[src]
fn cache_policy(&self) -> CachePolicy<&Self::Cached, ()>
[src]
impl CacheableResponse for isize
[src]
impl CacheableResponse for isize
[src]type Cached = isize
fn into_cache_policy(self) -> CachePolicy<Self::Cached, Self>
[src]
fn from_cached(cached: Self::Cached) -> Self
[src]
fn cache_policy(&self) -> CachePolicy<&Self::Cached, ()>
[src]
impl CacheableResponse for f32
[src]
impl CacheableResponse for f32
[src]type Cached = f32
fn into_cache_policy(self) -> CachePolicy<Self::Cached, Self>
[src]
fn from_cached(cached: Self::Cached) -> Self
[src]
fn cache_policy(&self) -> CachePolicy<&Self::Cached, ()>
[src]
impl CacheableResponse for f64
[src]
impl CacheableResponse for f64
[src]type Cached = f64
fn into_cache_policy(self) -> CachePolicy<Self::Cached, Self>
[src]
fn from_cached(cached: Self::Cached) -> Self
[src]
fn cache_policy(&self) -> CachePolicy<&Self::Cached, ()>
[src]
impl CacheableResponse for String
[src]
impl CacheableResponse for String
[src]type Cached = String
fn into_cache_policy(self) -> CachePolicy<Self::Cached, Self>
[src]
fn from_cached(cached: Self::Cached) -> Self
[src]
fn cache_policy(&self) -> CachePolicy<&Self::Cached, ()>
[src]
impl CacheableResponse for &'static str
[src]
impl CacheableResponse for &'static str
[src]type Cached = &'static str
fn into_cache_policy(self) -> CachePolicy<Self::Cached, Self>
[src]
fn from_cached(cached: Self::Cached) -> Self
[src]
fn cache_policy(&self) -> CachePolicy<&Self::Cached, ()>
[src]
impl CacheableResponse for bool
[src]
impl CacheableResponse for bool
[src]