1 unstable release

0.1.1 May 29, 2021
0.1.0 May 29, 2021
0.0.1 Apr 28, 2021

#188 in Caching

Download history 7/week @ 2024-03-14 49/week @ 2024-03-28 35/week @ 2024-04-04 12/week @ 2024-04-11 72/week @ 2024-04-18 45/week @ 2024-04-25 58/week @ 2024-05-02 42/week @ 2024-05-09 28/week @ 2024-05-16 15/week @ 2024-05-23 26/week @ 2024-05-30 30/week @ 2024-06-06 5/week @ 2024-06-13 5/week @ 2024-06-20 8/week @ 2024-06-27

54 downloads per month
Used in hitbox-actix

MIT license

65KB
1.5K SLoC

hitbox

Build status Coverage Status

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

Framework integrations

Features

  • Automatic cache key generation.
  • Multiple cache backend implementations:
  • Stale cache mechanics.
  • Cache locks for dogpile effect preventions.
  • Distributed cache locks.
  • Detailed metrics out of the box.

Backend implementations

  • Redis
  • In-memory backend

Feature flags

  • derive - Support for Cacheable trait derive macros.
  • metrics - Support for metrics.

Restrictions

Default cache key implementation based on serde_qs crate and have some restrictions.

Documentation

Example

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() }
}

Dependencies

~11MB
~194K SLoC