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
ttl option of Cachex.fetch
#195
Comments
This has been discussed before, but the decision was to avoid replicating options everywhere. In your case, you can do the following: with { :commit, _val } <- Cachex.fetch(:my_cache, cache_key, &my_func/1) do
Cachex.expire(:my_cache, cache_key, :timer.seconds(1)
{ :commit, val }
end |
Thanks for replying and sorry for the duplicated question :) Your solution is much cleaner and the codes might be: with { :commit, val } <- Cachex.fetch(:my_cache, cache_key, &my_func/1) do
Cachex.expire(:my_cache, cache_key, :timer.seconds(1))
val
else
{:ok, val} ->
val
_ ->
[]
end I might have to repeat this pattern several where and end up with a macro or something like that. This is not a big problem for developers though. |
I know this is a closed issue, and it wasn't the first of its kind, but I just wanted to add a +1 to the thought that I think this should be improved. As-is, it's both not-intuitive (and not really documented) and less than ideal. |
@karlseguin the issue is that there is a very obvious way of setting an expiration (it's right there in the public API). If I were to add a Even at this point, I'm unconvinced that |
I'll add my voice - I'm really very happy with Cachex, but I just wasted an hour or two debugging why I appreciate the fact the API is well documented, but it isn't obvious as it stands. Maybe documenting the possibilities of options in FWIW - my preference would be for the |
@mindok while I totally appreciate the difference in the API, the correct way to go is to simply remove it from While it sounds pretty simple to "just add it to I think maybe the documentation could be improved specifically on |
Thanks @whitfin - makes sense now. I've also had a dig around the codebase - I can see there's a fair bit of nuance there to keep things performant. I'll put together a PR with the following:
|
We got bitten by this as well. I wonder if raising an error when Thanks for the clear proposal at #195 (comment), much appreciated! |
Hi there, I was using Cachex to make a simple caching, some codes like below:
Unfortunately it doesn't work. After 1 second the cache is still available.
I went to the source code and figured out that the reason is that
ttl
option is not supported infetch
. I ended up with changingCachex.fetch
intoCachex.put
.Will it be better with
ttl
supported infetch
?thanks!
The text was updated successfully, but these errors were encountered: