mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #22200 from grosser/grosser/prepend
use prepend instead of extending every instance
This commit is contained in:
commit
ebe4e9b17c
3 changed files with 27 additions and 30 deletions
|
@ -10,6 +10,7 @@ module ActiveSupport
|
|||
# FileStore implements the Strategy::LocalCache strategy which implements
|
||||
# an in-memory cache inside of a block.
|
||||
class FileStore < Store
|
||||
prepend Strategy::LocalCache
|
||||
attr_reader :cache_path
|
||||
|
||||
DIR_FORMATTER = "%03X"
|
||||
|
@ -20,7 +21,6 @@ module ActiveSupport
|
|||
def initialize(cache_path, options = nil)
|
||||
super(options)
|
||||
@cache_path = cache_path.to_s
|
||||
extend Strategy::LocalCache
|
||||
end
|
||||
|
||||
# Deletes all items from the cache. In this case it deletes all the entries in the specified
|
||||
|
|
|
@ -24,6 +24,31 @@ module ActiveSupport
|
|||
# MemCacheStore implements the Strategy::LocalCache strategy which implements
|
||||
# an in-memory cache inside of a block.
|
||||
class MemCacheStore < Store
|
||||
# Provide support for raw values in the local cache strategy.
|
||||
module LocalCacheWithRaw # :nodoc:
|
||||
protected
|
||||
def read_entry(key, options)
|
||||
entry = super
|
||||
if options[:raw] && local_cache && entry
|
||||
entry = deserialize_entry(entry.value)
|
||||
end
|
||||
entry
|
||||
end
|
||||
|
||||
def write_entry(key, entry, options) # :nodoc:
|
||||
retval = super
|
||||
if options[:raw] && local_cache && retval
|
||||
raw_entry = Entry.new(entry.value.to_s)
|
||||
raw_entry.expires_at = entry.expires_at
|
||||
local_cache.write_entry(key, raw_entry, options)
|
||||
end
|
||||
retval
|
||||
end
|
||||
end
|
||||
|
||||
prepend Strategy::LocalCache
|
||||
prepend LocalCacheWithRaw
|
||||
|
||||
ESCAPE_KEY_CHARS = /[\x00-\x20%\x7F-\xFF]/n
|
||||
|
||||
# Creates a new Dalli::Client instance with specified addresses and options.
|
||||
|
@ -63,9 +88,6 @@ module ActiveSupport
|
|||
UNIVERSAL_OPTIONS.each{|name| mem_cache_options.delete(name)}
|
||||
@data = self.class.build_mem_cache(*(addresses + [mem_cache_options]))
|
||||
end
|
||||
|
||||
extend Strategy::LocalCache
|
||||
extend LocalCacheWithRaw
|
||||
end
|
||||
|
||||
# Reads multiple values from the cache using a single call to the
|
||||
|
@ -181,28 +203,6 @@ module ActiveSupport
|
|||
nil
|
||||
end
|
||||
end
|
||||
|
||||
# Provide support for raw values in the local cache strategy.
|
||||
module LocalCacheWithRaw # :nodoc:
|
||||
protected
|
||||
def read_entry(key, options)
|
||||
entry = super
|
||||
if options[:raw] && local_cache && entry
|
||||
entry = deserialize_entry(entry.value)
|
||||
end
|
||||
entry
|
||||
end
|
||||
|
||||
def write_entry(key, entry, options) # :nodoc:
|
||||
retval = super
|
||||
if options[:raw] && local_cache && retval
|
||||
raw_entry = Entry.new(entry.value.to_s)
|
||||
raw_entry.expires_at = entry.expires_at
|
||||
local_cache.write_entry(key, raw_entry, options)
|
||||
end
|
||||
retval
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,10 +8,7 @@ module ActiveSupport
|
|||
# be cached inside blocks that utilize this strategy. See
|
||||
# ActiveSupport::Cache::Strategy::LocalCache for more details.
|
||||
class NullStore < Store
|
||||
def initialize(options = nil)
|
||||
super(options)
|
||||
extend Strategy::LocalCache
|
||||
end
|
||||
prepend Strategy::LocalCache
|
||||
|
||||
def clear(options = nil)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue