-
Notifications
You must be signed in to change notification settings - Fork 4
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
allow option to not cache on non-zero exit code #25
Comments
Thanks for the FR, this is definitely a reasonable use-case. I'll have to think more about whether this makes sense to add and how to best enable per-invocation cache invalidation/rejection. What I would suggest instead is implementing the retry logic within your cached function, e.g. as a simple Consider also tuning the TTL or REFRESH; in particular reducing the REFRESH rate would minimize the amount of time a bad request is cached, while still using cached data when available, and ensuring a consistent and capped QPS to the backing function.
Plenty of commands return non-zero in meaningful situations, e.g.
This might not be an issue in your case, but it's worth calling out that you may actually want to cache such temporary failures in order to avoid cascading issues. If clients stop caching when they see a failure they will all be sending additional load to the backend right when it's become unhealthy, potentially making a bad problem worse.
Not too surprising :) I'm debating removing it outright. |
Thanks for the detailed response. A little more details about my use case - I have a small-ish utility script, with a function that makes some network calls that require a VPN connection. Sometimes I'm an idiot and forget to enable the VPN, so the cached response is basically garbage that I need to fix immediately. What I've done as a workaround is check the exit code of the call, and on non-zero I remove the cache. (The entire cache directory which is configured to be local to the directory of the script), which would be bad if I used it for more than one thing, but in this case gets me the desired behavior. |
Hah that's an effective workaround :) I could imagine adding a Thanks again for the FR, I will think further about how to support this better. |
As an update here, I've been working on I'll keep this open for now because it's still a valid FR for bash-cache, but it's not on my immediate radar especially now that |
cool thanks @dimo414 ! |
Looks similar to the idea there with |
Note that I am open to providing a way to ignore failed invocations, but the more bells and whistles you want in your caching layer the more I'd encourage you to look into |
Sometimes the expensive command I run fails. e.g. A brief network connectivity issue that I notice and fix after running the command. The problem when using bc::cache is that the result is cached. I'm not aware of a normal use scenario where I'd want the result to be cached on non-zero exit code, so that's my first suggestion.
If changing the default behavior isn't desired, it would be nice to allow the option to not cache on non-zero exit code.
p.s. I tried the memoize function, but it doesn't work for my scenario.
Thoughts?
The text was updated successfully, but these errors were encountered: