Skip to content

Commit

Permalink
release 0.48.0 / 0.19.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jaemk committed Jan 22, 2024
1 parent 3d6d79b commit df1cc17
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 33 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
## Changed
## Removed

## [0.48.0 / [cached_proc_macro[0.19.0]]]
## Added
- Add `CloneCached` trait with additional methods when the cache value type implements `Clone`
- Add `result_fallback` option to `cached` proc_macro to support re-using expired cache values
when utilizing an expiring cache store and a fallible function.
## Changed
## Removed

## [0.47.0]
## Added
## Changed
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cached"
version = "0.47.0"
version = "0.48.0"
authors = ["James Kominick <james@kominick.com>"]
description = "Generic cache implementations and simplified function memoization"
repository = "https://github.com/jaemk/cached"
Expand Down Expand Up @@ -29,7 +29,7 @@ redis_ahash = ["redis_store", "redis/ahash"]
wasm = ["instant/wasm-bindgen"]

[dependencies.cached_proc_macro]
version = "0.18.1"
version = "0.19.0"
path = "cached_proc_macro"
optional = true

Expand Down
2 changes: 1 addition & 1 deletion cached_proc_macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cached_proc_macro"
version = "0.18.1"
version = "0.19.0"
authors = ["csos95 <csoscss@gmail.com>", "James Kominick <james@kominick.com>"]
description = "Generic cache implementations and simplified function memoization"
repository = "https://github.com/jaemk/cached"
Expand Down
56 changes: 27 additions & 29 deletions cached_proc_macro/src/cached.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,39 +250,37 @@ pub fn cached(args: TokenStream, input: TokenStream) -> TokenStream {
#function_call
#set_cache_and_return
}
} else {
if args.result_fallback {
quote! {
let old_val = {
#lock
let (result, has_expired) = cache.cache_get_expired(&key);
if let (Some(result), false) = (result, has_expired) {
#return_cache_block
}
result
};
#function_call
} else if args.result_fallback {
quote! {
let old_val = {
#lock
let result = match (result.is_err(), old_val) {
(true, Some(old_val)) => {
Ok(old_val)
}
_ => result
};
#set_cache_and_return
}
} else {
quote! {
{
#lock
if let Some(result) = cache.cache_get(&key) {
#return_cache_block
}
let (result, has_expired) = cache.cache_get_expired(&key);
if let (Some(result), false) = (result, has_expired) {
#return_cache_block
}
result
};
#function_call
#lock
let result = match (result.is_err(), old_val) {
(true, Some(old_val)) => {
Ok(old_val)
}
#function_call
_ => result
};
#set_cache_and_return
}
} else {
quote! {
{
#lock
#set_cache_and_return
if let Some(result) = cache.cache_get(&key) {
#return_cache_block
}
}
#function_call
#lock
#set_cache_and_return
}
};

Expand Down
1 change: 1 addition & 0 deletions cached_proc_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use proc_macro::TokenStream;
/// - `result_fallback`: (optional, bool) If your function returns a `Result` and it fails, the cache will instead refresh the recently expired `Ok` value.
/// In other words, refreshes are best-effort - returning `Ok` refreshes as usual but `Err` falls back to the last `Ok`.
/// This is useful, for example, for keeping the last successful result of a network operation even during network disconnects.
/// *Note*, this option requires the cache type implements `CloneCached`.
///
/// ## Note
/// The `type`, `create`, `key`, and `convert` attributes must be in a `String`
Expand Down
2 changes: 1 addition & 1 deletion src/stores/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ mod async_redis {
key,
serde_json::to_string(&val)
.map_err(|e| RedisCacheError::CacheSerializationError { error: e })?,
self.seconds as u64,
self.seconds,
)
.ignore();

Expand Down

0 comments on commit df1cc17

Please sign in to comment.