cached icon indicating copy to clipboard operation
cached copied to clipboard

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

Open 0xForerunner opened this issue 2 years ago • 2 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
}

0xForerunner avatar Jan 19 '23 05:01 0xForerunner

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

0xForerunner avatar Jan 19 '23 20:01 0xForerunner

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(...);
}

omid avatar Apr 16 '24 21:04 omid