Skip to content

aikidos/memory-cache-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Actions Status

Simple local in-memory cache for Rust.

  1. Example
  2. Memoization
  3. Licence

See also Breaking Changes.

Example

use std::time::Duration;
use memory_cache::MemoryCache;

let mut cache = MemoryCache::new();

let key: &'static str = "key";
let value: &'static str = "Hello, World!";

// `None` - if the value must be kept forever.
let lifetime = Some(Duration::from_secs(30));

cache.insert(key, value, lifetime);

assert_eq!(cache.get(&key), Some(&value));
use once_cell::sync::Lazy;
use std::sync::Mutex;
use memory_cache::{MemoryCache, cached};

cached! {
    fn factorial(x: u128) -> u128 = {
        if x <= 1 {
            1
        } else {
            x * factorial(x - 1)
        }
    }
}

assert_eq!(factorial(21), 51090942171709440000);

Licence

MIT

About

Simple local in-memory cache for Rust.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages