Skip to content

Releases: c12i/simpl_cache

v2.4.1-beta

20 Mar 12:44
4749977
Compare
Choose a tag to compare

Improve proc macro error propagation

v2.4.0

14 Nov 12:56
777f2e7
Compare
Choose a tag to compare

Bug fixes and Improvements

  • Address BorrowMutError that occurred when annotating a recursive function with the ttl_cache crate: #4
  • Enable doc tests to catch bugs in docs: #3

v2.3.0-beta

16 Oct 11:21
e20ca90
Compare
Choose a tag to compare

New Changes

  • Add support for caching async functions
  • simple_cache_core crate import no longer required

v2.0.1-beta

14 Oct 15:13
a20bc52
Compare
Choose a tag to compare

New Changes

  • ttl_cache now expects a duration_s argument to explicitly state the cache duration
  • Added a only_ok argument to limit caching to Ok(T) variants from a function returning a Result<T, E> (#1)
  • Added a only_some argument to limit caching to Some(T) variants of an Option<T> (#1)

Examples

  • only_ok
// only_ok option ensures that only .is_ok values from the returning Result are cached
#[ttl_cache(duration_s = 30, only_ok = true)] 
fn some_fallible_function(n: u32) -> Result<u32, String> {
    if n == 0 {
        return Err(String::from("zeros are not allowed"))
    }
    Ok(n)
}

fn main() {
     // zero is not cached since function returns an Err since n == 0
    println!("last: {}", some_fallible_function(0));
    // cache miss: 10 is cached since the result is_ok
    println!("last: {}", some_fallible_function(10));
    // cache hit: 10 is retrieved from the cache
    println!("last: {}", some_fallible_function(10));

}
  • only_some
// only_some option ensures that only .is_some values from the returning Option are cached
#[ttl_cache(duration_s = 30, only_some = true)] 
fn some_optional_function(n: u32) -> Option<u32> {
    if n == 0 {
        return None;
    }
    Some(n)
}

fn main() {
     // zero is not cached since function returns None since n == 0
    println!("last: {}", some_optional_function(0));
    // cache miss: 10 is cached since the result is_some
    println!("last: {}", some_optional_function(10));
    // cache hit: 10 is retrieved from the cache
    println!("last: {}", some_optional_function(10));

}

v1.0.0 beta

10 Aug 11:01
405a812
Compare
Choose a tag to compare
  • Release ttl_cache proc macro