Skip to content
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

Closed
wants to merge 6 commits into from
Closed

Perforated array caching #352

wants to merge 6 commits into from

Conversation

sorentwo
Copy link

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):

  • It relies on the objects already being serializers, of course that is never the case
  • ArrayCaching#serialize needs a real implementation

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.
@coveralls
Copy link

Coverage Status

Coverage increased (+0%) when pulling 7e8f812 on sorentwo:perforated-array-caching into 8ac4bf9 on rails-api:master.

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.
@coveralls
Copy link

Coverage Status

Coverage increased (+0%) when pulling 3f3601c on sorentwo:perforated-array-caching into 8ac4bf9 on rails-api:master.

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.
@coveralls
Copy link

Coverage Status

Coverage increased (+0%) when pulling 592f3ed on sorentwo:perforated-array-caching into 8ac4bf9 on rails-api:master.

@sorentwo
Copy link
Author

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.

@sorentwo
Copy link
Author

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.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 3e5b1d6 on sorentwo:perforated-array-caching into 8ac4bf9 on rails-api:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0%) when pulling b456283 on sorentwo:perforated-array-caching into 8ac4bf9 on rails-api:master.

@sorentwo
Copy link
Author

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.

@sorentwo
Copy link
Author

Preemptively closing this before @spastorino gets to it. Caching was removed from serializers, so this no longer applies.

@sorentwo sorentwo closed this Oct 21, 2013
@spastorino
Copy link
Contributor

@sorentwo lol

@spastorino
Copy link
Contributor

thanks BTW

@sorentwo
Copy link
Author

@spastorino NP, thanks for your refactoring work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants