#cache #redis

mouscache_derive

A utility crate implement trait to store object either in redis or in memory

6 releases

Uses old Rust 2015

0.4.0 Apr 27, 2018
0.3.3 Apr 24, 2018
0.2.0 Apr 18, 2018

#63 in Caching

Download history 49/week @ 2021-06-05 25/week @ 2021-06-12 12/week @ 2021-06-19 24/week @ 2021-06-26 41/week @ 2021-07-03 51/week @ 2021-07-10 18/week @ 2021-07-17 37/week @ 2021-07-24 18/week @ 2021-07-31 8/week @ 2021-08-07 9/week @ 2021-08-14 5/week @ 2021-08-21 4/week @ 2021-09-11 6/week @ 2021-09-18

190 downloads per month
Used in qui-vive

MIT license

10KB
212 lines

mouscache-rs

Mouscache doc badge dependency status

A small lib to manipulate object with redis or an in-memory cache

Basic Usage

use mouscache;

#[derive(Cacheable, Clone, Debug)]
struct YourData {
    field1: u16,
    field2: String,
}

fn main() {
    let data = YourData {
        field1: 42,
        field2: String::from("Hello, World!"),
    };

    if let Ok(mut cache) = mouscache::redis("localhost", None) {
        let _ = cache.insert("test", data.clone());

        let data2: YourData = cache.get("test").unwrap();

        assert_eq!(data.field1, data2.field1);
        assert_eq!(data.field2, data2.field2);
    }
}

Customizing What's Being Cached

Mouscache now support 2 custom attribute to customize entry :

expires Attribute

Specifies a duration in sec after which the entry is invalid

use mouscache;

#[derive(Cacheable, Clone, Debug)]
#[cache(expires="10")] // each entry of type YouCustomDataType will be valid 10 sec.
struct YouCustomDataType {
    yourPrecious_field: String
}

rename Attribute

Specifies the name which will be used to insert the entry

use mouscache;

#[derive(Cacheable, Clone, Debug)]
#[cache(rename="ThisNameIsCooler")] // each entry of type YouCustomDataType will be inserted with ThisNameIsCooler
struct YouCustomDataType {
    yourPrecious_field: String
}

##TODO

  • Add support for struct with named field
  • Add Data Attribute
  • Add support for unnamed field
  • Add support for enum

Dependencies

~1.5MB
~43K SLoC