cached_resource icon indicating copy to clipboard operation
cached_resource copied to clipboard

Cache write on 404 and other errors

Open franciscomasi opened this issue 7 years ago • 4 comments

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?

franciscomasi avatar Dec 11 '18 13:12 franciscomasi

You should be able to force a reload.

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

Daniel-ltw avatar Dec 11 '18 22:12 Daniel-ltw

@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?

mhgbrown avatar Dec 12 '18 10:12 mhgbrown

@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.

franciscomasi avatar Dec 12 '18 12:12 franciscomasi

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

mhgbrown avatar Dec 13 '18 12:12 mhgbrown