memcached_store 2.3.0 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cdd4f8408b915953e5dac445736ee15ddb7db1208acf365fdecb5a03b389a8e8
4
- data.tar.gz: 218294aa36469941f5ef0a6609d31687ead001e25c42dc1cf8b565b5e36e395c
3
+ metadata.gz: 51f58b245ce09f4f36a9f095684357fecc3e6ec3a7dfcfe5d37c532c94f3476a
4
+ data.tar.gz: b5062194ad1fc584c122bfedfc2e9b11f04e05080c702753623b1dc599042885
5
5
  SHA512:
6
- metadata.gz: 774a57bfa30dd07824d9a8b4bcb394de38fea2e59a2cae280bc583dcd92d3ece84241c5bffc54162d903f0f594e7fbb50b7f54c19f56fe74744c8089af60c93d
7
- data.tar.gz: b0b35daa5e372df41f17d51c41df7daa393c441447342800e213e1333bdec1b574ed0cd3f72e2523105f56fcce73b34cf65ecceb68f30ca26d2058413b611484
6
+ metadata.gz: 7a0023120d7e6107600871075ece41c802d076fa670ba2ad588bd0a15017544499c88a281f8ab0f6ce067f6179728af0a991013fb7ed0851305776b2cf11b853
7
+ data.tar.gz: 8aac93c1733e645bbc683eb3d8e6e2099ef553866f0fc9a7278bb4e008190e09df783963bca99c72d00152ecf0bf94eee29582146f5e2c411d587697a5062158
@@ -1,5 +1,6 @@
1
1
  # file havily based out off https://github.com/rails/rails/blob/3-2-stable/activesupport/lib/active_support/cache/mem_cache_store.rb
2
2
  require 'digest/md5'
3
+ require 'delegate'
3
4
 
4
5
  module ActiveSupport
5
6
  module Cache
@@ -66,7 +67,13 @@ module ActiveSupport
66
67
  @swallow_exceptions = true
67
68
  @swallow_exceptions = options.delete(:swallow_exceptions) if options.key?(:swallow_exceptions)
68
69
 
69
- super(options)
70
+ if options.key?(:coder)
71
+ raise ArgumentError, "ActiveSupport::Cache::MemcachedStore doesn't support custom coders"
72
+ end
73
+
74
+ # We don't use a coder, so we set it to nil so Active Support don't think we're using
75
+ # a deprecated one.
76
+ super(options.merge(coder: nil))
70
77
 
71
78
  if addresses.first.is_a?(Memcached)
72
79
  @connection = addresses.first
@@ -127,18 +134,27 @@ module ActiveSupport
127
134
  def cas(name, options = nil)
128
135
  options = merged_options(options)
129
136
  key = normalize_key(name, options)
137
+ payload = nil
130
138
 
131
- handle_exceptions(return_value_on_error: false) do
139
+ success = handle_exceptions(return_value_on_error: false) do
132
140
  instrument(:cas, name, options) do
133
141
  @connection.cas(key, expiration(options)) do |raw_value|
134
142
  entry = deserialize_entry(raw_value)
135
143
  value = yield entry.value
136
144
  break true if read_only
137
- serialize_entry(Entry.new(value, **options), options)
145
+ payload = serialize_entry(Entry.new(value, **options), options)
138
146
  end
139
147
  end
140
148
  true
141
149
  end
150
+
151
+ if success
152
+ local_cache.write_entry(key, payload) if local_cache
153
+ else
154
+ local_cache.delete_entry(key) if local_cache
155
+ end
156
+
157
+ success
142
158
  end
143
159
 
144
160
  def cas_multi(*names, **options)
@@ -147,9 +163,11 @@ module ActiveSupport
147
163
  options = merged_options(options)
148
164
  keys_to_names = Hash[names.map { |name| [normalize_key(name, options), name] }]
149
165
 
166
+ sent_payloads = nil
167
+
150
168
  handle_exceptions(return_value_on_error: false) do
151
169
  instrument(:cas_multi, names, options) do
152
- @connection.cas(keys_to_names.keys, expiration(options)) do |raw_values|
170
+ written_payloads = @connection.cas(keys_to_names.keys, expiration(options)) do |raw_values|
153
171
  values = {}
154
172
 
155
173
  raw_values.each do |key, raw_value|
@@ -165,8 +183,19 @@ module ActiveSupport
165
183
  [normalize_key(name, options), serialize_entry(Entry.new(value, **options), options)]
166
184
  end
167
185
 
168
- Hash[serialized_values]
186
+ sent_payloads = Hash[serialized_values]
169
187
  end
188
+
189
+ if local_cache && sent_payloads
190
+ sent_payloads.each_key do |key|
191
+ if written_payloads.key?(key)
192
+ local_cache.write_entry(key, written_payloads[key])
193
+ else
194
+ local_cache.delete_entry(key)
195
+ end
196
+ end
197
+ end
198
+
170
199
  true
171
200
  end
172
201
  end
@@ -215,21 +244,21 @@ module ActiveSupport
215
244
  private
216
245
 
217
246
  if private_method_defined?(:read_serialized_entry)
218
- class LocalStore < Strategy::LocalCache::LocalStore
247
+ class DupLocalStore < DelegateClass(Strategy::LocalCache::LocalStore)
219
248
  def write_entry(_key, entry)
220
249
  if entry.is_a?(Entry)
221
- entry.dup_value!
250
+ entry.dup_value!
222
251
  end
223
252
  super
224
253
  end
225
254
 
226
255
  def fetch_entry(key)
227
- entry = @data.fetch(key) do
256
+ entry = super do
228
257
  new_entry = yield
229
258
  if entry.is_a?(Entry)
230
259
  new_entry.dup_value!
231
260
  end
232
- @data[key] = new_entry
261
+ new_entry
233
262
  end
234
263
  entry = entry.dup
235
264
 
@@ -241,12 +270,17 @@ module ActiveSupport
241
270
  end
242
271
  end
243
272
 
244
- module LocalCacheDup
245
- def with_local_cache
246
- use_temporary_local_cache(LocalStore.new) { yield }
273
+ module DupLocalCache
274
+ private
275
+
276
+ def local_cache
277
+ if local_cache = super
278
+ DupLocalStore.new(local_cache)
279
+ end
247
280
  end
248
281
  end
249
- prepend LocalCacheDup
282
+
283
+ prepend DupLocalCache
250
284
 
251
285
  def read_entry(key, **options) # :nodoc:
252
286
  deserialize_entry(read_serialized_entry(key, **options))
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module MemcachedStore
3
- VERSION = "2.3.0"
3
+ VERSION = "2.3.2"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memcached_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Camilo Lopez
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2021-07-26 00:00:00.000000000 Z
14
+ date: 2023-07-26 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  - !ruby/object:Gem::Version
121
121
  version: '0'
122
122
  requirements: []
123
- rubygems_version: 3.2.20
123
+ rubygems_version: 3.4.16
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: Plugin-able Memcached adapters to add features (compression, safety)