Shopify / response_bank

Simple response caching for Ruby applications
http://www.shopify.com
MIT License
135 stars 18 forks source link

Fix raw cache usage consistency #53

Closed casperisfine closed 3 years ago

casperisfine commented 3 years ago

Not all AS::Cache backends are capable of reading raw values without being told specifically to do so, for instance Rails 6.1 RedisCacheStore:

>> cache = ActiveSupport::Cache::RedisCacheStore.new
=> #<ActiveSupport::Cache::RedisCacheStore options={:namespace=>nil, :compress=>true, :compress_threshold=>1024, :expires_in=>nil, :race_condition_ttl=>nil} redis={}>
>> cache.write('foo', 'bar', raw: true)
=> "OK"
>> cache.read('foo')
activesupport-6.1.4/lib/active_support/core_ext/marshal.rb:8:in `load': incompatible marshal file format (can't be read) (TypeError)

So it's preferable to read with raw: true.