memcached_store 2.1.5 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4635e49b33c70f622363339dda844ed847785724779b9fa7820d4a34dbf372f8
4
- data.tar.gz: 2371f00c595f4b9fb5f4fd37621a591e8ac11125b53467dbbd990febfa9296d9
3
+ metadata.gz: cdd4f8408b915953e5dac445736ee15ddb7db1208acf365fdecb5a03b389a8e8
4
+ data.tar.gz: 218294aa36469941f5ef0a6609d31687ead001e25c42dc1cf8b565b5e36e395c
5
5
  SHA512:
6
- metadata.gz: 18831e059e7db2fae9d3733baa244f2ba69050bfc1d72ecd72dd80332a0e525b50a409f98cb76d224450fce01919e29695ba3c5585cadc42bfaef1b66474ac72
7
- data.tar.gz: cc44c59b08101ac3934ce59b90c89179d0b88c64dd519d265b81e76adbb09c8d3e2f5b4445e7de6e8c73973df615c46a613a29dd5f9c0db8acfa6d2c788d4445
6
+ metadata.gz: 774a57bfa30dd07824d9a8b4bcb394de38fea2e59a2cae280bc583dcd92d3ece84241c5bffc54162d903f0f594e7fbb50b7f54c19f56fe74744c8089af60c93d
7
+ data.tar.gz: b0b35daa5e372df41f17d51c41df7daa393c441447342800e213e1333bdec1b574ed0cd3f72e2523105f56fcce73b34cf65ecceb68f30ca26d2058413b611484
@@ -58,6 +58,8 @@ module ActiveSupport
58
58
 
59
59
  attr_accessor :read_only, :swallow_exceptions
60
60
 
61
+ prepend(Strategy::LocalCache)
62
+
61
63
  def initialize(*addresses, **options)
62
64
  addresses = addresses.flatten
63
65
  options[:codec] ||= Codec.new
@@ -76,8 +78,6 @@ module ActiveSupport
76
78
  UNIVERSAL_OPTIONS.each { |name| mem_cache_options.delete(name) }
77
79
  @connection = Memcached.new([*addresses, *servers], mem_cache_options)
78
80
  end
79
-
80
- extend Strategy::LocalCache
81
81
  end
82
82
 
83
83
  def append(name, value, options = nil)
@@ -212,64 +212,106 @@ 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
280
+ end
281
+
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
264
291
  end
292
+ end
265
293
 
266
- def escape_key(key)
267
- key
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
268
299
  end
269
300
  end
270
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
- if value
314
+ unless value.nil?
273
315
  value.is_a?(Entry) ? value : Entry.new(value, compress: false)
274
316
  end
275
317
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module MemcachedStore
3
- VERSION = "2.1.5"
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.1.5
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: 2020-05-25 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,28 +19,28 @@ 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
33
33
  requirements:
34
34
  - - "~>"
35
35
  - !ruby/object:Gem::Version
36
- version: 1.8.0
36
+ version: '1.8'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - "~>"
42
42
  - !ruby/object:Gem::Version
43
- version: 1.8.0
43
+ version: '1.8'
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: rake
46
46
  requirement: !ruby/object:Gem::Requirement
@@ -55,6 +55,34 @@ dependencies:
55
55
  - - ">="
56
56
  - !ruby/object:Gem::Version
57
57
  version: '0'
58
+ - !ruby/object:Gem::Dependency
59
+ name: mocha
60
+ requirement: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ - !ruby/object:Gem::Dependency
73
+ name: timecop
74
+ requirement: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
58
86
  description: Plugin-able Memcached adapters to add features (compression, safety)
59
87
  email:
60
88
  - camilo@camilolopez.com
@@ -85,14 +113,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
113
  requirements:
86
114
  - - ">="
87
115
  - !ruby/object:Gem::Version
88
- version: 2.2.0
116
+ version: 2.6.0
89
117
  required_rubygems_version: !ruby/object:Gem::Requirement
90
118
  requirements:
91
119
  - - ">="
92
120
  - !ruby/object:Gem::Version
93
121
  version: '0'
94
122
  requirements: []
95
- rubygems_version: 3.0.3
123
+ rubygems_version: 3.2.20
96
124
  signing_key:
97
125
  specification_version: 4
98
126
  summary: Plugin-able Memcached adapters to add features (compression, safety)