Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Improve MemCacheStoreCAS patch to properly pass serialized entries to Dalli.

## 1.6.4

- Patch `run_callbacks` instead of `_run_commit_callbacks` to expire cache prior to `after_commit` callbacks. (#602)
Expand Down
23 changes: 8 additions & 15 deletions lib/identity_cache/mem_cache_store_cas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

module IdentityCache
module MemCacheStoreCAS
Entry = ActiveSupport::Cache::Entry

def cas(name, options = nil)
options = merged_options(options)
key = normalize_key(name, options)
Expand All @@ -12,10 +14,10 @@ def cas(name, options = nil)
instrument(:cas, key, options) do
@data.with do |connection|
connection.cas(key, options[:expires_in].to_i, options) do |raw_value|
entry = deserialize_entry(raw_value, raw: options[:raw])
entry = deserialize_entry(raw_value, **options)
value = yield entry.value
entry = ActiveSupport::Cache::Entry.new(value, **options)
options[:raw] ? entry.value.to_s : entry
entry = Entry.new(value, **options, version: normalize_version(name, options))
serialize_entry(entry, **options)
end
end
end
Expand All @@ -34,7 +36,7 @@ def cas_multi(*names, **options)

values = {}
raw_values.each do |key, raw_value|
entry = deserialize_entry(raw_value.first, raw: options[:raw])
entry = deserialize_entry(raw_value.first, **options)
values[keys_to_names[key]] = entry.value unless entry.expired?
end

Expand All @@ -43,21 +45,12 @@ def cas_multi(*names, **options)
updates.each do |name, value|
key = normalize_key(name, options)
cas_id = raw_values[key].last
entry = ActiveSupport::Cache::Entry.new(value, **options)
payload = options[:raw] ? entry.value.to_s : entry
entry = Entry.new(value, **options)
payload = serialize_entry(entry, **options)
@data.with { |c| c.replace_cas(key, payload, cas_id, options[:expires_in].to_i, options) }
end
end
end
end

if ActiveSupport::Cache::MemCacheStore.instance_method(:deserialize_entry).arity == 1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is no longer necessary as we require Rails >= 7.0


private

def deserialize_entry(payload, raw: nil)
super(payload)
end
end
end
end
Loading