memcached_store 2.2.1 → 2.3.0

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: 8c2e6e07846db81c341bc513b655a969c805145f55c52f601692a5b6a8044c82
4
- data.tar.gz: 0fb5ae2adb9fabee93ee7f0b5256a0f768354434cb6adc6b1191f987ce8198f4
3
+ metadata.gz: cdd4f8408b915953e5dac445736ee15ddb7db1208acf365fdecb5a03b389a8e8
4
+ data.tar.gz: 218294aa36469941f5ef0a6609d31687ead001e25c42dc1cf8b565b5e36e395c
5
5
  SHA512:
6
- metadata.gz: 1ac0741c64d3a5fe6d58915656d6d29984a133d41d6ce84f07535486ea1a707acad670831458f60b6d4fa8a25ea4de1b7e2cee7c03948b6c11c676b9bd595572
7
- data.tar.gz: f683b364d84ebd7672ca9cfd3c6f00e5941730aec8636a07147f1a0a8277d3cc0c73eb686a028f316a2c36c7d34e43051621e4f15bc14860dac781246acc6d19
6
+ metadata.gz: 774a57bfa30dd07824d9a8b4bcb394de38fea2e59a2cae280bc583dcd92d3ece84241c5bffc54162d903f0f594e7fbb50b7f54c19f56fe74744c8089af60c93d
7
+ data.tar.gz: b0b35daa5e372df41f17d51c41df7daa393c441447342800e213e1333bdec1b574ed0cd3f72e2523105f56fcce73b34cf65ecceb68f30ca26d2058413b611484
@@ -212,62 +212,104 @@ module ActiveSupport
212
212
  end
213
213
  end
214
214
 
215
- protected
215
+ private
216
216
 
217
- def read_entry(key, _options) # :nodoc:
218
- handle_exceptions(return_value_on_error: nil) do
219
- deserialize_entry(@connection.get(escape_key(key)))
217
+ if private_method_defined?(:read_serialized_entry)
218
+ class LocalStore < Strategy::LocalCache::LocalStore
219
+ def write_entry(_key, entry)
220
+ if entry.is_a?(Entry)
221
+ entry.dup_value!
222
+ end
223
+ super
224
+ end
225
+
226
+ def fetch_entry(key)
227
+ entry = @data.fetch(key) do
228
+ new_entry = yield
229
+ if entry.is_a?(Entry)
230
+ new_entry.dup_value!
231
+ end
232
+ @data[key] = new_entry
233
+ end
234
+ entry = entry.dup
235
+
236
+ if entry.is_a?(Entry)
237
+ entry.dup_value!
238
+ end
239
+
240
+ entry
241
+ end
220
242
  end
221
- end
222
243
 
223
- def write_entry(key, entry, options) # :nodoc:
224
- return true if read_only
225
- method = options && options[:unless_exist] ? :add : :set
226
- expires_in = expiration(options)
227
- value = serialize_entry(entry, options)
228
- handle_exceptions(return_value_on_error: false) do
229
- @connection.send(method, escape_key(key), value, expires_in)
230
- true
244
+ module LocalCacheDup
245
+ def with_local_cache
246
+ use_temporary_local_cache(LocalStore.new) { yield }
247
+ end
231
248
  end
232
- end
249
+ prepend LocalCacheDup
233
250
 
234
- def delete_entry(key, _options) # :nodoc:
235
- return true if read_only
236
- handle_exceptions(return_value_on_error: false, on_miss: true) do
237
- @connection.delete(escape_key(key))
238
- true
251
+ def read_entry(key, **options) # :nodoc:
252
+ deserialize_entry(read_serialized_entry(key, **options))
239
253
  end
240
- end
241
254
 
242
- private
255
+ def read_serialized_entry(key, **)
256
+ handle_exceptions(return_value_on_error: nil) do
257
+ @connection.get(key)
258
+ end
259
+ end
260
+
261
+ def write_entry(key, entry, **options) # :nodoc:
262
+ return true if read_only
243
263
 
244
- if ActiveSupport::VERSION::MAJOR < 5
245
- def normalize_key(key, options)
246
- escape_key(namespaced_key(key, options))
264
+ write_serialized_entry(key, serialize_entry(entry, **options), **options)
247
265
  end
248
266
 
249
- def escape_key(key)
250
- key = key.to_s.dup
251
- key = key.force_encoding(Encoding::ASCII_8BIT)
252
- key = key.gsub(ESCAPE_KEY_CHARS) { |match| "%#{match.getbyte(0).to_s(16).upcase}" }
253
- key = "#{key[0, 213]}:md5:#{Digest::MD5.hexdigest(key)}" if key.size > 250
254
- key
267
+ def write_serialized_entry(key, value, **options)
268
+ method = options && options[:unless_exist] ? :add : :set
269
+ expires_in = expiration(options)
270
+ handle_exceptions(return_value_on_error: false) do
271
+ @connection.send(method, key, value, expires_in)
272
+ true
273
+ end
255
274
  end
256
275
  else
257
- def normalize_key(key, options)
258
- key = super.dup
259
- key = key.force_encoding(Encoding::ASCII_8BIT)
260
- key = key.gsub(ESCAPE_KEY_CHARS) { |match| "%#{match.getbyte(0).to_s(16).upcase}" }
261
- # When we remove support to Rails 5.1 we can change the code to use ActiveSupport::Digest
262
- key = "#{key[0, 213]}:md5:#{::Digest::MD5.hexdigest(key)}" if key.size > 250
263
- key
276
+ def read_entry(key, _options) # :nodoc:
277
+ handle_exceptions(return_value_on_error: nil) do
278
+ deserialize_entry(@connection.get(key))
279
+ end
264
280
  end
265
281
 
266
- def escape_key(key)
267
- key
282
+ def write_entry(key, entry, options) # :nodoc:
283
+ return true if read_only
284
+ method = options && options[:unless_exist] ? :add : :set
285
+ expires_in = expiration(options)
286
+ value = serialize_entry(entry, options)
287
+ handle_exceptions(return_value_on_error: false) do
288
+ @connection.send(method, key, value, expires_in)
289
+ true
290
+ end
268
291
  end
269
292
  end
270
293
 
294
+ def delete_entry(key, _options) # :nodoc:
295
+ return true if read_only
296
+ handle_exceptions(return_value_on_error: false, on_miss: true) do
297
+ @connection.delete(key)
298
+ true
299
+ end
300
+ end
301
+
302
+ private
303
+
304
+ def normalize_key(key, options)
305
+ key = super.dup
306
+ key = key.force_encoding(Encoding::ASCII_8BIT)
307
+ key = key.gsub(ESCAPE_KEY_CHARS) { |match| "%#{match.getbyte(0).to_s(16).upcase}" }
308
+ # When we remove support to Rails 5.1 we can change the code to use ActiveSupport::Digest
309
+ key = "#{key[0, 213]}:md5:#{::Digest::MD5.hexdigest(key)}" if key.size > 250
310
+ key
311
+ end
312
+
271
313
  def deserialize_entry(value)
272
314
  unless value.nil?
273
315
  value.is_a?(Entry) ? value : Entry.new(value, compress: false)
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module MemcachedStore
3
- VERSION = "2.2.1"
3
+ VERSION = "2.3.0"
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.2.1
4
+ version: 2.3.0
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-05-27 00:00:00.000000000 Z
14
+ date: 2021-07-26 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -19,14 +19,14 @@ dependencies:
19
19
  requirements:
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: '4'
22
+ version: '6'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '4'
29
+ version: '6'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: memcached
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -113,14 +113,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - ">="
115
115
  - !ruby/object:Gem::Version
116
- version: 2.2.0
116
+ version: 2.6.0
117
117
  required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  requirements:
119
119
  - - ">="
120
120
  - !ruby/object:Gem::Version
121
121
  version: '0'
122
122
  requirements: []
123
- rubygems_version: 3.2.17
123
+ rubygems_version: 3.2.20
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: Plugin-able Memcached adapters to add features (compression, safety)