Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions lib/active_support/cache/memcached_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ def initialize(*addresses, **options)
def append(name, value, options = nil)
return true if read_only
options = merged_options(options)
normalized_key = normalize_key(name, options)
key = normalize_key(name, options)

handle_exceptions(return_value_on_error: nil, on_miss: false, miss_exceptions: [Memcached::NotStored]) do
instrument(:append, name) do
@connection.append(normalized_key, value)
instrument(:append, name_or_key(name, key)) do
@connection.append(key, value)
end
true
end
Expand All @@ -119,7 +119,7 @@ def read_multi(*names)
values = {}

handle_exceptions(return_value_on_error: {}) do
instrument(:read_multi, names, options) do
instrument(:read_multi, name_or_key(names, keys_to_names), options) do
if raw_values = @connection.get(keys_to_names.keys)
raw_values.each do |key, value|
entry = deserialize_entry(value)
Expand All @@ -137,7 +137,7 @@ def cas(name, options = nil)
payload = nil

success = handle_exceptions(return_value_on_error: false) do
instrument(:cas, name, options) do
instrument(:cas, name_or_key(name, key), options) do
@connection.cas(key, expiration(options)) do |raw_value|
entry = deserialize_entry(raw_value)
value = yield entry.value
Expand Down Expand Up @@ -166,7 +166,7 @@ def cas_multi(*names, **options)
sent_payloads = nil

handle_exceptions(return_value_on_error: false) do
instrument(:cas_multi, names, options) do
instrument(:cas_multi, name_or_key(names, keys_to_names), options) do
written_payloads = @connection.cas(keys_to_names.keys, expiration(options)) do |raw_values|
values = {}

Expand Down Expand Up @@ -203,18 +203,20 @@ def cas_multi(*names, **options)

def increment(name, amount = 1, options = nil) # :nodoc:
options = merged_options(options)
key = normalize_key(name, options)
handle_exceptions(return_value_on_error: nil) do
instrument(:increment, name, amount: amount) do
@connection.incr(normalize_key(name, options), amount)
instrument(:increment, name_or_key(name, key), amount: amount) do
@connection.incr(key, amount)
end
end
end

def decrement(name, amount = 1, options = nil) # :nodoc:
options = merged_options(options)
key = normalize_key(name, options)
handle_exceptions(return_value_on_error: nil) do
instrument(:decrement, name, amount: amount) do
@connection.decr(normalize_key(name, options), amount)
instrument(:decrement, name_or_key(name, key), amount: amount) do
@connection.decr(key, amount)
end
end
end
Expand Down Expand Up @@ -344,6 +346,16 @@ def normalize_key(key, options)
key
end

if ActiveSupport.gem_version >= Gem::Version.new("7.2.0.alpha")
def name_or_key(name, key)
key
end
else
def name_or_key(name, key)
name
end
end

def deserialize_entry(value)
unless value.nil?
value.is_a?(Entry) ? value : Entry.new(value, compress: false)
Expand Down