Skip to content

Commit 596fd7f

Browse files
authored
Merge pull request #624 from byroot/cas-serialization
Improve MemCacheStoreCAS patch to properly pass serialized entries to Dalli
2 parents 4e468b9 + 150ae4e commit 596fd7f

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Improve MemCacheStoreCAS patch to properly pass serialized entries to Dalli.
6+
57
## 1.6.4
68

79
- Patch `run_callbacks` instead of `_run_commit_callbacks` to expire cache prior to `after_commit` callbacks. (#602)

lib/identity_cache/mem_cache_store_cas.rb

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
module IdentityCache
66
module MemCacheStoreCAS
7+
Entry = ActiveSupport::Cache::Entry
8+
79
def cas(name, options = nil)
810
options = merged_options(options)
911
key = normalize_key(name, options)
@@ -12,10 +14,10 @@ def cas(name, options = nil)
1214
instrument(:cas, key, options) do
1315
@data.with do |connection|
1416
connection.cas(key, options[:expires_in].to_i, options) do |raw_value|
15-
entry = deserialize_entry(raw_value, raw: options[:raw])
17+
entry = deserialize_entry(raw_value, **options)
1618
value = yield entry.value
17-
entry = ActiveSupport::Cache::Entry.new(value, **options)
18-
options[:raw] ? entry.value.to_s : entry
19+
entry = Entry.new(value, **options, version: normalize_version(name, options))
20+
serialize_entry(entry, **options)
1921
end
2022
end
2123
end
@@ -34,7 +36,7 @@ def cas_multi(*names, **options)
3436

3537
values = {}
3638
raw_values.each do |key, raw_value|
37-
entry = deserialize_entry(raw_value.first, raw: options[:raw])
39+
entry = deserialize_entry(raw_value.first, **options)
3840
values[keys_to_names[key]] = entry.value unless entry.expired?
3941
end
4042

@@ -43,21 +45,12 @@ def cas_multi(*names, **options)
4345
updates.each do |name, value|
4446
key = normalize_key(name, options)
4547
cas_id = raw_values[key].last
46-
entry = ActiveSupport::Cache::Entry.new(value, **options)
47-
payload = options[:raw] ? entry.value.to_s : entry
48+
entry = Entry.new(value, **options)
49+
payload = serialize_entry(entry, **options)
4850
@data.with { |c| c.replace_cas(key, payload, cas_id, options[:expires_in].to_i, options) }
4951
end
5052
end
5153
end
5254
end
53-
54-
if ActiveSupport::Cache::MemCacheStore.instance_method(:deserialize_entry).arity == 1
55-
56-
private
57-
58-
def deserialize_entry(payload, raw: nil)
59-
super(payload)
60-
end
61-
end
6255
end
6356
end

0 commit comments

Comments
 (0)