Trait hitbox_actix::Cacheable[][src]

pub trait Cacheable {
    fn cache_key(&self) -> Result<String, CacheError>;
fn cache_key_prefix(&self) -> String; fn cache_ttl(&self) -> u32 { ... }
fn cache_stale_ttl(&self) -> u32 { ... }
fn cache_version(&self) -> u32 { ... } }
Expand description

Trait describes cache configuration per type that implements this trait.

Required methods

fn cache_key(&self) -> Result<String, CacheError>[src]

Method should return unique identifier for struct object.

In cache storage it may prepends with cache version and Upstream name.

Examples

use hitbox::cache::Cacheable;
use hitbox::CacheError;

struct QueryNothing {
    id: Option<i32>,
}

impl Cacheable for QueryNothing {
    fn cache_key(&self) -> Result<String, CacheError> {
        let key = format!("{}::id::{}", self.cache_key_prefix(), self.id.map_or_else(
            || "None".to_owned(), |id| id.to_string())
        );
        Ok(key)
    }
    fn cache_key_prefix(&self) -> String { "database::QueryNothing".to_owned() }
}

let query = QueryNothing { id: Some(1) };
assert_eq!(query.cache_key().unwrap(), "database::QueryNothing::id::1");
let query = QueryNothing { id: None };
assert_eq!(query.cache_key().unwrap(), "database::QueryNothing::id::None");

fn cache_key_prefix(&self) -> String[src]

Method return cache key prefix based on message type.

Provided methods

fn cache_ttl(&self) -> u32[src]

Describe time-to-live (ttl) value for cache storage in seconds.

After that time value will be removed from cache storage.

fn cache_stale_ttl(&self) -> u32[src]

Describe expire\stale timeout value for cache storage in seconds.

After that time cached value marked as stale.

|__cache_is_valid__|__cache_is_stale__| -> time
                   ^                  ^
                stale_ttl       ttl (cache evicted)

fn cache_version(&self) -> u32[src]

Describe current cache version for this type.

Implementors