https://github.com/devolutions/mouscache-rs
An in-memory or distributed memory cache, with style
https://github.com/devolutions/mouscache-rs
Last synced: about 2 months ago
JSON representation
An in-memory or distributed memory cache, with style
- Host: GitHub
- URL: https://github.com/devolutions/mouscache-rs
- Owner: Devolutions
- License: mit
- Created: 2018-04-18T13:42:50.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-03-10T15:48:24.000Z (almost 4 years ago)
- Last Synced: 2025-06-19T22:07:58.675Z (8 months ago)
- Language: Rust
- Homepage:
- Size: 69.3 KB
- Stars: 7
- Watchers: 15
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# mouscache-rs
[](https://docs.rs/mouscache/)
[](https://deps.rs/repo/github/Devolutions/mouscache-rs)
A small lib to manipulate object with redis or an in-memory cache
## Basic Usage
```rust
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
```rust
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
```rust
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
- [x] Add support for `struct` with named field
- [x] Add Data Attribute
- [ ] Add support for unnamed field
- [ ] Add support for `enum`