A small lib to manipulate object with redis or an in-memory cache
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);
}
}
Mouscache now support 2 custom attribute to customize entry :
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
}
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