#cache #redis

mouscache

A crate to store object either in redis or in memory

25 releases

0.5.6 Aug 3, 2020
0.5.5 Nov 26, 2019
0.5.4 May 28, 2019
0.5.3 Jan 29, 2019
0.5.1 Jul 23, 2018

#21 in Caching

Download history 80/week @ 2020-06-06 57/week @ 2020-06-13 14/week @ 2020-06-20 50/week @ 2020-06-27 59/week @ 2020-07-04 67/week @ 2020-07-11 55/week @ 2020-07-18 26/week @ 2020-07-25 54/week @ 2020-08-01 72/week @ 2020-08-08 83/week @ 2020-08-15 43/week @ 2020-08-22 55/week @ 2020-08-29 107/week @ 2020-09-05 42/week @ 2020-09-12 17/week @ 2020-09-19

243 downloads per month
Used in qui-vive

MIT license

44KB
1K SLoC

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

~5.5MB
~117K SLoC