JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Caching not working with RedisStore Cache
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 2.3k
- Forks
- 546
- PR merge metrics
- No merged PRs in 30d
Description
Using Rails.cache as a resource_cache appears to make the caching fail when config.cache_store is redis_store.
I think the reason is due to the way Redis Cache serialise key as string when they are arrays.
When the key(an array) is serialised in the self.write method of CachedResourceFragment
https://github.com/cerebris/jsonapi-resources/blob/master/lib/jsonapi/cached_resource_fragment.rb#L122 it is serialised as a string.
When the value is retrieved in the lookup method the hash hits returned by the read_multi methods has keys that are not array, but strings. The method has_key? is then failing returning false instead of true.
https://github.com/cerebris/jsonapi-resources/blob/master/lib/jsonapi/cached_resource_fragment.rb#L81
Simple example, with config.cache_store = :redis_store
Rails.cache.write([1,2], 'value')
hash = Rails.cache.read_multi([1,2])
# returns false
hash.has_key?([1,2])
I've tried to serialise manually the keys (https://github.com/cerebris/jsonapi-resources/compare/master...x4d3:master) without success, the test are failing.
Thank you,
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lib/jsonapi/cached_resource_fragment.rb at lookup and self.write, then reproduce the Rails.cache.read_multi example with config.cache_store set to :redis_store. Compare the key types returned by RedisStore with the array keys used by has_key?; done means cache hits are recognized and the existing tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rails, redis, ruby
- Domain
- backend, performance
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100