Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sj26/6c9ddc1740e40b95c0db to your computer and use it in GitHub Desktop.
Save sj26/6c9ddc1740e40b95c0db to your computer and use it in GitHub Desktop.
# By default, DalliStore doesn't deal with `raw` correctly when inside the
# LocalCache per-request middleware. The MemCacheClient fixes this already by
# adding another little module. Let's do the same.
#
# A PR has been lodged upstream:
#
# https://github.com/mperham/dalli/pull/481
#
# Once merged @sj26 will update dalli and remove this workaround.
if defined? ActiveSupport::Cache::DalliStore and Rails.cache.is_a? ActiveSupport::Cache::DalliStore
module DalliStoreLocalCacheEntryUnwrapAndRaw # :nodoc:
protected
def read_entry(key, options)
retval = super
if retval.is_a? ActiveSupport::Cache::Entry
# Must have come from LocalStore, unwrap it
if options[:raw]
retval.value.to_s
else
retval.value
end
else
retval
end
end
end
Rails.cache.extend DalliStoreLocalCacheEntryUnwrapAndRaw
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment