Created
August 6, 2015 05:09
-
-
Save sj26/6c9ddc1740e40b95c0db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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