#cache #redis

mouscache

A crate to store object either in redis or in memory

21 unstable releases (3 breaking)

0.5.2 Aug 9, 2018
0.5.1 Jul 23, 2018
0.5.0 Jun 26, 2018
0.4.9 Jun 18, 2018
0.2.0 Apr 18, 2018

#5 in Caching

Download history 2/week @ 2018-05-18 19/week @ 2018-05-25 75/week @ 2018-06-01 13/week @ 2018-06-08 141/week @ 2018-06-15 87/week @ 2018-06-22 139/week @ 2018-06-29 70/week @ 2018-07-06 32/week @ 2018-07-13 77/week @ 2018-07-20 175/week @ 2018-07-27 89/week @ 2018-08-03 432/week @ 2018-08-10

450 downloads per month
Used in 1 crate

MIT license

45KB
1K SLoC

mouscache-rs

Mouscache doc badge

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

~8.5MB
~210K SLoC