jaemk / cached

Rust cache structures and easy function memoization

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: bool function argument that forces a cache refresh.

ewoolsey opened this issue · comments

Here is an example using Rocket. This feature would really clean up my code base.

#[cached(result = true, time = 5, sync_writes = true, force_refresh = refresh)] // This is an example of how the macro could look
#[get("/market-state?<refresh>")]
pub async fn market_state(refresh: bool) -> ApiResult<(ContentType, String)> {
    // Do some async stuff
}

Would probably make sense for this parameter to automatically be excluded from the key!

Just write a private function and put cached around the private function only.

Then in the public function write something like:

if refresh {
  private_function_prime_cache(...);
} else {
  private_function(...);
}