You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As far as I can tell from source code there is no memoization of fetched cache value for later cached method calls on the same object. Is it on purpose?
To be honest, this behavior seems to be pretty surprising:
classFooincludeCacheablecacheable:bardefbar"foo"endendfoo=Foo.newfoo.bar# cache read and deserializationfoo.bar# cache read and deserializationfoo.bar# cache read and deserialization
Context: recently I saw a Rails app in the wild that cached some ActiveRecord model methods that in turn returned another ActiveRecord objects. And some places got terribly slow due to dozens of repeated calls to retrieve and deserialize which is especially slow and compute-intensive for AR objects, see this blog post for details (and yes, I know that doing so is a bad idea per se). So I had to get rid of cacheable in favor of pure memoization or manual caching with following memoization.
The text was updated successfully, but these errors were encountered:
You should be able to add your own cache adapter based on the :memory adapter that uses memoization and falls back on some other cache like the Rails.cache.
As far as I can tell from source code there is no memoization of fetched cache value for later cached method calls on the same object. Is it on purpose?
To be honest, this behavior seems to be pretty surprising:
Context: recently I saw a Rails app in the wild that cached some ActiveRecord model methods that in turn returned another ActiveRecord objects. And some places got terribly slow due to dozens of repeated calls to retrieve and deserialize which is especially slow and compute-intensive for AR objects, see this blog post for details (and yes, I know that doing so is a bad idea per se). So I had to get rid of cacheable in favor of pure memoization or manual caching with following memoization.
The text was updated successfully, but these errors were encountered: