mhgbrown / cached_resource

Caching for ActiveResource
MIT License
80 stars 28 forks source link

Use ActiveSupport::JSON.decode to parse from cache #47

Closed bjedrocha closed 3 years ago

bjedrocha commented 4 years ago

Under the hood, ActiveResource uses ActiveSupport::JSON.decode to parse JSON. Unlike JSON.parse, ActiveSupport::JSON.decode will convert any strings it recognizes as dates/times into their corresponding objects if ActiveSupport.parse_json_times is enabled. Ref.

Thus currently if ActiveSupport.parse_json_times is enabled, the data returned from cache is inconsistent with what is returned from ActiveResource directly. This change fixes the inconsistency by also using ActiveSupport::JSON.decode to parse the JSON from cache.

bjedrocha commented 4 years ago

My only question, is string keys the norm or symbol keys the norm?

I think at this point it's personal preference, especially with newer versions of Ruby. In this specific case though it doesn't matter since the hash returned by ActiveSupport::JSON.decode is only used internally and not returned as part of the public interface.

bjedrocha commented 3 years ago

@Daniel-ltw I managed to fix the failing CI build. Are you good to merge this and cut a new version?

Daniel-ltw commented 3 years ago

Merged and updated the version on master branch.

Will allow @mhgbrown to build and release the gem.

mhgbrown commented 3 years ago

@bjedrocha and @Daniel-ltw thanks! Will get to it soon!

mhgbrown commented 3 years ago

released: https://rubygems.org/gems/cached_resource/versions/5.1.3