Crates.io | hitbox |
lib.rs | hitbox |
version | 0.1.1 |
source | src |
created_at | 2021-04-28 21:20:47.730158 |
updated_at | 2021-05-29 21:05:08.129653 |
description | Asynchronous caching framework in Rust. |
homepage | |
repository | https://github.com/hit-box/hitbox/ |
max_upload_size | |
id | 390771 |
size | 74,923 |
Hitbox is an asynchronous caching framework supporting multiple backends and suitable for distributed and for single-machine applications.
Default cache key implementation based on serde_qs crate and have some restrictions.
Dependencies:
[dependencies]
hitbox = "0.1"
Code:
NOTE: Default cache key implementation based on serde_qs crate and have some restrictions.
First, you should derive Cacheable trait for your struct or enum:
use hitbox::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Cacheable, Serialize)] // With features=["derive"]
struct Ping {
id: i32,
}
Or implement that trait manually:
use hitbox::{Cacheable, CacheError};
struct Ping { id: i32 }
impl Cacheable for Ping {
fn cache_key(&self) -> Result<String, CacheError> {
Ok(format!("{}::{}", self.cache_key_prefix(), self.id))
}
fn cache_key_prefix(&self) -> String { "Ping".to_owned() }
}