#hitbox #cache #cache-backend #macro-derive #async #actix

macro hitbox-derive

Derive macros for asynchronous caching framework in Rust

1 unstable release

0.1.1 May 29, 2021
0.1.0 May 29, 2021

#5 in #cache-backend


Used in 2 crates (via hitbox)

MIT license

8KB
111 lines

hitbox-derive

Hitbox is an asynchronous caching framework supporting multiple backends and suitable for distributed and for single-machine applications.

hitbox-derive is Cacheable and CacheableResponse trait derive macro implementation.


lib.rs:

This crate provides default implementations for Cacheable and CacheableResponse derive macros.

You can see an example of Cacheable derive macro below:

use hitbox::cache::Cacheable;
use hitbox::error::CacheError;
use serde::Serialize;

#[derive(Cacheable, Serialize)]
#[cache_ttl(120)]
#[cache_stale_ttl(100)]
#[cache_version(100)]
struct Message {
    field: i32,
};
let message = Message { field: 42 };
assert_eq!(message.cache_message_key().unwrap(), "Message::v100::field=42".to_string());

CacheableResponse example:

use hitbox::response::CacheableResponse;
use serde::Serialize;

#[derive(CacheableResponse, Serialize)]
pub enum MyResult {
    OptionOne(i32),
    OptionTwo(String),
}

Dependencies

~1.2–1.7MB
~39K SLoC