Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ewoolsey opened this issue Jan 19, 2023 · 2 comments
Open

Comments

@ewoolsey
Copy link

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
}
@ewoolsey
Copy link
Author

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

@omid
Copy link
Contributor

omid commented Apr 16, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants