mhgbrown / cached_resource

Caching for ActiveResource
MIT License
80 stars 28 forks source link

Cache write on 404 and other errors #44

Open franciscomasi opened 5 years ago

franciscomasi commented 5 years ago

Hello! I have problems with cached_resource because when a resource is not found, the cache is updated with the error. For example when execute MyActiveResource.first, this return http status code 404 and cache is updated with nil. If i run again MyActiveResource.first, the cache return nil. Is it correct that before an error the cache is updated?

Daniel-ltw commented 5 years ago

You should be able to force a reload.

@mhgbrown do you think the gem should handle this? if nil, attempt a reload.

mhgbrown commented 5 years ago

@Daniel-ltw hmm, this is a good q. Perhaps it can be an option? In combination with like a max_retries or something?

@franciscomasi does forcing a reload solve your problem for now?

franciscomasi commented 5 years ago

@Daniel-ltw @mhgbrown In principle it is a good alternative solution. I should modify the MyActiveResource class in some way so that, in case the result is null, try at least one more time using the recharge. Otherwise, I should include in each call a validation for the recharge, which leads me to modify many lines of code in many applications.

mhgbrown commented 5 years ago

Ok, gotcha. You want to maybe submit a PR @franciscomasi 😉😎? Otherwise, @Daniel-ltw or I can hopefully make some time to check it out...