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

Caching not working with RedisStore Cache #917

Open
x4d3 opened this issue Dec 1, 2016 · 3 comments
Open

Caching not working with RedisStore Cache #917

x4d3 opened this issue Dec 1, 2016 · 3 comments

Comments

@x4d3
Copy link

x4d3 commented Dec 1, 2016

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 (master...x4d3:master) without success, the test are failing.

Thank you,

@x4d3 x4d3 changed the title Caching not working with RedisStore cache. Caching not working with RedisStore cache Dec 1, 2016
@x4d3 x4d3 changed the title Caching not working with RedisStore cache Caching not working with RedisStore Cache Dec 1, 2016
@DavidMikeSimon
Copy link
Contributor

Thank you for the bug report, I'll look into this

@DavidMikeSimon
Copy link
Contributor

DavidMikeSimon commented Dec 8, 2016

@x4d3 I'm not able to reproduce your example results using RedisStore.

irb(main):001:0> require 'redis-rails'
=> true

irb(main):003:0> c = ActiveSupport::Cache::RedisStore.new
=> #<ActiveSupport::Cache::RedisStore:0x00000001288010 @options={}, @data=#<Redis client v3.3.2 for redis://127.0.0.1:6379/0>>

irb(main):005:0> c.write([1,2], 'value')
=> "OK"

irb(main):008:0> h = c.read_multi([1,2])
=> {[1, 2]=>"value"}

irb(main):009:0> h.has_key?([1,2])
=> true

Could you try again with the current version of redis-rails? Also, in production on my own app, I'm getting good results with the readthis gem.

@DavidMikeSimon
Copy link
Contributor

@lgebhardt I'd recommend closing this issue, I'm unable to reproduce this bug.

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

No branches or pull requests

2 participants