#cache #redis

mouscache

A crate to store object either in redis or in memory

24 releases

✓ Uses Rust 2018 edition

0.5.5 Nov 26, 2019
0.5.4 May 28, 2019
0.5.3 Jan 29, 2019
0.5.2 Aug 9, 2018
0.5.1 Jul 23, 2018

#9 in Caching

Download history 7/week @ 2019-08-13 270/week @ 2019-08-20 84/week @ 2019-08-27 99/week @ 2019-09-03 36/week @ 2019-09-10 260/week @ 2019-09-17 90/week @ 2019-09-24 109/week @ 2019-10-01 21/week @ 2019-10-08 94/week @ 2019-10-15 95/week @ 2019-10-22 41/week @ 2019-10-29 29/week @ 2019-11-05 31/week @ 2019-11-12 74/week @ 2019-11-19

335 downloads per month
Used in 1 crate

MIT license

46KB
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

~5MB
~112K SLoC