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
Perforated array caching #352
Conversation
Rather than caching the array as a solid entity this leverages the cache's `fetch_multi` method to construct array json from the underlying objects in a cached array. Using this method any existing object caches can be used to when constructing the cached array, and individual entities will be cached for later usage.
By breaking apart the mapping of objects into serializers and the mapping of serializers into a hash we gain exposure to the interim array of serializer objects. This is required to make array caching work without re-implementing all of the serializer mapping logic.
Both #to_json and #serialize are implemented along with some important fixes and refinements: * Expose an `expanded_cache_key` method within the caching module. * Disable caching on objects within the array to prevent duplicate caching. * Key objects based on the expanded cache key to ensure a match between individual object and array object caching.
Those last couple of commits hit all of the points I mentioned above, so this is potentially ready to go. I'll squash it up if/when somebody takes a look at it. |
I wasn't aware that fetch_multi was only added back in April and isn't part of Rails 4.0.0 or lower. I'll re-implement with backward compatibility. |
After learning that AMS is in a state of flux without any exact caching strategy I went ahead and built my own array serializer. I've pushed up any changes that I've discovered along the way for reference at least. |
Preemptively closing this before @spastorino gets to it. Caching was removed from serializers, so this no longer applies. |
@sorentwo lol |
thanks BTW |
@spastorino NP, thanks for your refactoring work! |
Rather than caching the array as a solid entity this leverages the cache's
fetch_multi
method to construct array json from the underlying objects in a cached array. Using this method any existing object caches can be used to when constructing the cached array, and individual entities will be cached for later usage.There are a couple of cases and improvements that still need to be made before this would be ready to go, but I wanted to open it up for discussion. This is something I've used internally for about a year now (as a custom wrapper) and would really like to see it available for wider usage.
Features that are still missing (or don't have a test case exposing the errors):