activesupport 4.2.0 → 5.0.0.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activesupport might be problematic. Click here for more details.

Files changed (185) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +630 -220
  3. data/MIT-LICENSE +2 -2
  4. data/README.rdoc +2 -3
  5. data/lib/active_support/array_inquirer.rb +44 -0
  6. data/lib/active_support/backtrace_cleaner.rb +1 -1
  7. data/lib/active_support/benchmarkable.rb +1 -1
  8. data/lib/active_support/cache/file_store.rb +36 -22
  9. data/lib/active_support/cache/mem_cache_store.rb +63 -54
  10. data/lib/active_support/cache/memory_store.rb +16 -21
  11. data/lib/active_support/cache/null_store.rb +1 -4
  12. data/lib/active_support/cache/strategy/local_cache.rb +31 -20
  13. data/lib/active_support/cache.rb +73 -89
  14. data/lib/active_support/callbacks.rb +195 -155
  15. data/lib/active_support/concern.rb +2 -2
  16. data/lib/active_support/concurrency/latch.rb +7 -15
  17. data/lib/active_support/concurrency/share_lock.rb +186 -0
  18. data/lib/active_support/configurable.rb +1 -0
  19. data/lib/active_support/core_ext/array/access.rb +27 -1
  20. data/lib/active_support/core_ext/array/conversions.rb +6 -4
  21. data/lib/active_support/core_ext/array/grouping.rb +9 -18
  22. data/lib/active_support/core_ext/array/inquiry.rb +17 -0
  23. data/lib/active_support/core_ext/array/wrap.rb +5 -4
  24. data/lib/active_support/core_ext/array.rb +1 -0
  25. data/lib/active_support/core_ext/big_decimal/conversions.rb +8 -10
  26. data/lib/active_support/core_ext/class/attribute.rb +10 -9
  27. data/lib/active_support/core_ext/class/subclasses.rb +3 -4
  28. data/lib/active_support/core_ext/class.rb +0 -1
  29. data/lib/active_support/core_ext/date/blank.rb +12 -0
  30. data/lib/active_support/core_ext/date/calculations.rb +1 -1
  31. data/lib/active_support/core_ext/date/conversions.rb +13 -6
  32. data/lib/active_support/core_ext/date.rb +1 -1
  33. data/lib/active_support/core_ext/date_and_time/calculations.rb +109 -25
  34. data/lib/active_support/core_ext/date_and_time/compatibility.rb +18 -0
  35. data/lib/active_support/core_ext/date_and_time/zones.rb +3 -4
  36. data/lib/active_support/core_ext/date_time/blank.rb +12 -0
  37. data/lib/active_support/core_ext/date_time/calculations.rb +36 -10
  38. data/lib/active_support/core_ext/date_time/compatibility.rb +5 -0
  39. data/lib/active_support/core_ext/date_time/conversions.rb +2 -0
  40. data/lib/active_support/core_ext/date_time.rb +2 -1
  41. data/lib/active_support/core_ext/enumerable.rb +49 -5
  42. data/lib/active_support/core_ext/file/atomic.rb +30 -25
  43. data/lib/active_support/core_ext/hash/conversions.rb +23 -4
  44. data/lib/active_support/core_ext/hash/deep_merge.rb +1 -1
  45. data/lib/active_support/core_ext/hash/except.rb +9 -8
  46. data/lib/active_support/core_ext/hash/indifferent_access.rb +1 -1
  47. data/lib/active_support/core_ext/hash/keys.rb +23 -19
  48. data/lib/active_support/core_ext/hash/slice.rb +1 -1
  49. data/lib/active_support/core_ext/hash/transform_values.rb +11 -5
  50. data/lib/active_support/core_ext/integer/time.rb +1 -16
  51. data/lib/active_support/core_ext/kernel/concern.rb +2 -0
  52. data/lib/active_support/core_ext/kernel/debugger.rb +3 -10
  53. data/lib/active_support/core_ext/kernel/reporting.rb +2 -83
  54. data/lib/active_support/core_ext/kernel.rb +0 -1
  55. data/lib/active_support/core_ext/load_error.rb +4 -2
  56. data/lib/active_support/core_ext/marshal.rb +12 -11
  57. data/lib/active_support/core_ext/module/aliasing.rb +6 -1
  58. data/lib/active_support/core_ext/module/anonymous.rb +10 -1
  59. data/lib/active_support/core_ext/module/attr_internal.rb +2 -5
  60. data/lib/active_support/core_ext/module/attribute_accessors.rb +15 -15
  61. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +141 -0
  62. data/lib/active_support/core_ext/module/concerning.rb +4 -4
  63. data/lib/active_support/core_ext/module/delegation.rb +35 -25
  64. data/lib/active_support/core_ext/module/deprecation.rb +2 -2
  65. data/lib/active_support/core_ext/module/introspection.rb +4 -0
  66. data/lib/active_support/core_ext/module/method_transplanting.rb +3 -11
  67. data/lib/active_support/core_ext/module/qualified_const.rb +30 -12
  68. data/lib/active_support/core_ext/module/remove_method.rb +23 -0
  69. data/lib/active_support/core_ext/module.rb +1 -0
  70. data/lib/active_support/core_ext/name_error.rb +15 -2
  71. data/lib/active_support/core_ext/numeric/bytes.rb +20 -0
  72. data/lib/active_support/core_ext/numeric/conversions.rb +74 -64
  73. data/lib/active_support/core_ext/numeric/inquiry.rb +26 -0
  74. data/lib/active_support/core_ext/numeric/time.rb +24 -19
  75. data/lib/active_support/core_ext/numeric.rb +1 -0
  76. data/lib/active_support/core_ext/object/blank.rb +17 -5
  77. data/lib/active_support/core_ext/object/deep_dup.rb +10 -3
  78. data/lib/active_support/core_ext/object/duplicable.rb +8 -13
  79. data/lib/active_support/core_ext/object/inclusion.rb +2 -2
  80. data/lib/active_support/core_ext/object/instance_variables.rb +1 -1
  81. data/lib/active_support/core_ext/object/json.rb +15 -7
  82. data/lib/active_support/core_ext/object/to_query.rb +1 -1
  83. data/lib/active_support/core_ext/object/try.rb +68 -22
  84. data/lib/active_support/core_ext/object/with_options.rb +1 -1
  85. data/lib/active_support/core_ext/object.rb +0 -1
  86. data/lib/active_support/core_ext/range/conversions.rb +18 -6
  87. data/lib/active_support/core_ext/range/each.rb +16 -18
  88. data/lib/active_support/core_ext/range/include_range.rb +20 -20
  89. data/lib/active_support/core_ext/securerandom.rb +23 -0
  90. data/lib/active_support/core_ext/string/access.rb +1 -1
  91. data/lib/active_support/core_ext/string/behavior.rb +1 -1
  92. data/lib/active_support/core_ext/string/conversions.rb +4 -3
  93. data/lib/active_support/core_ext/string/filters.rb +5 -5
  94. data/lib/active_support/core_ext/string/inflections.rb +32 -5
  95. data/lib/active_support/core_ext/string/multibyte.rb +11 -7
  96. data/lib/active_support/core_ext/string/output_safety.rb +18 -16
  97. data/lib/active_support/core_ext/string/strip.rb +3 -6
  98. data/lib/active_support/core_ext/struct.rb +3 -6
  99. data/lib/active_support/core_ext/time/calculations.rb +36 -11
  100. data/lib/active_support/core_ext/time/compatibility.rb +5 -0
  101. data/lib/active_support/core_ext/time/conversions.rb +4 -2
  102. data/lib/active_support/core_ext/time/marshal.rb +2 -29
  103. data/lib/active_support/core_ext/time/zones.rb +36 -4
  104. data/lib/active_support/core_ext/time.rb +1 -1
  105. data/lib/active_support/core_ext/uri.rb +1 -3
  106. data/lib/active_support/core_ext.rb +2 -1
  107. data/lib/active_support/dependencies/interlock.rb +51 -0
  108. data/lib/active_support/dependencies.rb +87 -95
  109. data/lib/active_support/deprecation/behaviors.rb +16 -2
  110. data/lib/active_support/deprecation/method_wrappers.rb +42 -16
  111. data/lib/active_support/deprecation/proxy_wrappers.rb +47 -24
  112. data/lib/active_support/deprecation/reporting.rb +23 -5
  113. data/lib/active_support/deprecation.rb +1 -1
  114. data/lib/active_support/duration/iso8601_parser.rb +122 -0
  115. data/lib/active_support/duration/iso8601_serializer.rb +51 -0
  116. data/lib/active_support/duration.rb +55 -10
  117. data/lib/active_support/evented_file_update_checker.rb +194 -0
  118. data/lib/active_support/execution_wrapper.rb +117 -0
  119. data/lib/active_support/executor.rb +6 -0
  120. data/lib/active_support/file_update_checker.rb +23 -3
  121. data/lib/active_support/gem_version.rb +4 -4
  122. data/lib/active_support/hash_with_indifferent_access.rb +46 -13
  123. data/lib/active_support/i18n_railtie.rb +25 -4
  124. data/lib/active_support/inflector/inflections.rb +36 -5
  125. data/lib/active_support/inflector/methods.rb +97 -90
  126. data/lib/active_support/inflector/transliterate.rb +36 -21
  127. data/lib/active_support/json/decoding.rb +11 -10
  128. data/lib/active_support/json/encoding.rb +4 -49
  129. data/lib/active_support/key_generator.rb +7 -9
  130. data/lib/active_support/locale/en.yml +2 -0
  131. data/lib/active_support/log_subscriber/test_helper.rb +3 -3
  132. data/lib/active_support/log_subscriber.rb +1 -1
  133. data/lib/active_support/logger.rb +50 -1
  134. data/lib/active_support/logger_silence.rb +8 -4
  135. data/lib/active_support/logger_thread_safe_level.rb +31 -0
  136. data/lib/active_support/message_encryptor.rb +4 -4
  137. data/lib/active_support/message_verifier.rb +70 -8
  138. data/lib/active_support/multibyte/chars.rb +13 -4
  139. data/lib/active_support/multibyte/unicode.rb +44 -21
  140. data/lib/active_support/notifications/fanout.rb +6 -6
  141. data/lib/active_support/notifications/instrumenter.rb +20 -2
  142. data/lib/active_support/notifications.rb +2 -2
  143. data/lib/active_support/number_helper/number_to_currency_converter.rb +7 -9
  144. data/lib/active_support/number_helper/number_to_delimited_converter.rb +8 -3
  145. data/lib/active_support/number_helper/number_to_human_converter.rb +6 -4
  146. data/lib/active_support/number_helper/number_to_human_size_converter.rb +6 -2
  147. data/lib/active_support/number_helper/number_to_percentage_converter.rb +1 -1
  148. data/lib/active_support/number_helper/number_to_phone_converter.rb +11 -2
  149. data/lib/active_support/number_helper/number_to_rounded_converter.rb +30 -25
  150. data/lib/active_support/number_helper.rb +90 -67
  151. data/lib/active_support/ordered_hash.rb +1 -1
  152. data/lib/active_support/ordered_options.rb +15 -1
  153. data/lib/active_support/per_thread_registry.rb +8 -3
  154. data/lib/active_support/rails.rb +2 -2
  155. data/lib/active_support/railtie.rb +6 -1
  156. data/lib/active_support/reloader.rb +129 -0
  157. data/lib/active_support/rescuable.rb +93 -47
  158. data/lib/active_support/security_utils.rb +7 -0
  159. data/lib/active_support/string_inquirer.rb +1 -1
  160. data/lib/active_support/subscriber.rb +5 -10
  161. data/lib/active_support/tagged_logging.rb +3 -1
  162. data/lib/active_support/test_case.rb +15 -29
  163. data/lib/active_support/testing/assertions.rb +15 -13
  164. data/lib/active_support/testing/autorun.rb +8 -1
  165. data/lib/active_support/testing/deprecation.rb +9 -8
  166. data/lib/active_support/testing/file_fixtures.rb +34 -0
  167. data/lib/active_support/testing/isolation.rb +22 -8
  168. data/lib/active_support/testing/method_call_assertions.rb +41 -0
  169. data/lib/active_support/testing/stream.rb +42 -0
  170. data/lib/active_support/testing/time_helpers.rb +13 -10
  171. data/lib/active_support/time_with_zone.rb +135 -46
  172. data/lib/active_support/values/time_zone.rb +95 -47
  173. data/lib/active_support/values/unicode_tables.dat +0 -0
  174. data/lib/active_support/xml_mini/jdom.rb +7 -6
  175. data/lib/active_support/xml_mini/libxml.rb +2 -2
  176. data/lib/active_support/xml_mini/nokogiri.rb +2 -2
  177. data/lib/active_support/xml_mini/rexml.rb +7 -8
  178. data/lib/active_support/xml_mini.rb +22 -14
  179. data/lib/active_support.rb +20 -6
  180. metadata +33 -35
  181. data/lib/active_support/core_ext/big_decimal/yaml_conversions.rb +0 -14
  182. data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -45
  183. data/lib/active_support/core_ext/date_time/zones.rb +0 -6
  184. data/lib/active_support/core_ext/object/itself.rb +0 -15
  185. data/lib/active_support/core_ext/thread.rb +0 -86
@@ -8,7 +8,7 @@ require 'active_support/core_ext/numeric/bytes'
8
8
  require 'active_support/core_ext/numeric/time'
9
9
  require 'active_support/core_ext/object/to_param'
10
10
  require 'active_support/core_ext/string/inflections'
11
- require 'active_support/deprecation'
11
+ require 'active_support/core_ext/string/strip'
12
12
 
13
13
  module ActiveSupport
14
14
  # See ActiveSupport::Cache::Store for documentation.
@@ -27,7 +27,7 @@ module ActiveSupport
27
27
  end
28
28
 
29
29
  class << self
30
- # Creates a new CacheStore object according to the given options.
30
+ # Creates a new Store object according to the given options.
31
31
  #
32
32
  # If no arguments are passed to this method, then a new
33
33
  # ActiveSupport::Cache::MemoryStore object will be returned.
@@ -158,20 +158,20 @@ module ActiveSupport
158
158
  attr_reader :silence, :options
159
159
  alias :silence? :silence
160
160
 
161
- # Create a new cache. The options will be passed to any write method calls
161
+ # Creates a new cache. The options will be passed to any write method calls
162
162
  # except for <tt>:namespace</tt> which can be used to set the global
163
163
  # namespace for the cache.
164
164
  def initialize(options = nil)
165
165
  @options = options ? options.dup : {}
166
166
  end
167
167
 
168
- # Silence the logger.
168
+ # Silences the logger.
169
169
  def silence!
170
170
  @silence = true
171
171
  self
172
172
  end
173
173
 
174
- # Silence the logger within a block.
174
+ # Silences the logger within a block.
175
175
  def mute
176
176
  previous_silence, @silence = defined?(@silence) && @silence, true
177
177
  yield
@@ -179,18 +179,6 @@ module ActiveSupport
179
179
  @silence = previous_silence
180
180
  end
181
181
 
182
- # :deprecated:
183
- def self.instrument=(boolean)
184
- ActiveSupport::Deprecation.warn "ActiveSupport::Cache.instrument= is deprecated and will be removed in Rails 5. Instrumentation is now always on so you can safely stop using it."
185
- true
186
- end
187
-
188
- # :deprecated:
189
- def self.instrument
190
- ActiveSupport::Deprecation.warn "ActiveSupport::Cache.instrument is deprecated and will be removed in Rails 5. Instrumentation is now always on so you can safely stop using it."
191
- true
192
- end
193
-
194
182
  # Fetches data from the cache, using the given key. If there is data in
195
183
  # the cache with the given key, then that data is returned.
196
184
  #
@@ -210,10 +198,17 @@ module ActiveSupport
210
198
  # cache.fetch('city') # => "Duckburgh"
211
199
  #
212
200
  # You may also specify additional options via the +options+ argument.
213
- # Setting <tt>force: true</tt> will force a cache miss:
201
+ # Setting <tt>force: true</tt> forces a cache "miss," meaning we treat
202
+ # the cache value as missing even if it's present. Passing a block is
203
+ # required when `force` is true so this always results in a cache write.
214
204
  #
215
205
  # cache.write('today', 'Monday')
216
- # cache.fetch('today', force: true) # => nil
206
+ # cache.fetch('today', force: true) { 'Tuesday' } # => 'Tuesday'
207
+ # cache.fetch('today', force: true) # => ArgumentError
208
+ #
209
+ # The `:force` option is useful when you're calling some other method to
210
+ # ask whether you should force a cache write. Otherwise, it's clearer to
211
+ # just call `Cache#write`.
217
212
  #
218
213
  # Setting <tt>:compress</tt> will store a large cache entry set by the call
219
214
  # in a compressed format.
@@ -267,10 +262,11 @@ module ActiveSupport
267
262
  # end
268
263
  # end
269
264
  #
270
- # # val_1 => "new value 1"
271
- # # val_2 => "original value"
272
- # # sleep 10 # First thread extend the life of cache by another 10 seconds
273
- # # cache.fetch('foo') => "new value 1"
265
+ # cache.fetch('foo') # => "original value"
266
+ # sleep 10 # First thread extended the life of cache by another 10 seconds
267
+ # cache.fetch('foo') # => "new value 1"
268
+ # val_1 # => "new value 1"
269
+ # val_2 # => "original value"
274
270
  #
275
271
  # Other options will be handled by the specific cache store implementation.
276
272
  # Internally, #fetch calls #read_entry, and calls #write_entry on a cache
@@ -288,16 +284,23 @@ module ActiveSupport
288
284
  def fetch(name, options = nil)
289
285
  if block_given?
290
286
  options = merged_options(options)
291
- key = namespaced_key(name, options)
287
+ key = normalize_key(name, options)
292
288
 
293
- cached_entry = find_cached_entry(key, name, options) unless options[:force]
294
- entry = handle_expired_entry(cached_entry, key, options)
289
+ entry = nil
290
+ instrument(:read, name, options) do |payload|
291
+ cached_entry = read_entry(key, options) unless options[:force]
292
+ entry = handle_expired_entry(cached_entry, key, options)
293
+ payload[:super_operation] = :fetch if payload
294
+ payload[:hit] = !!entry if payload
295
+ end
295
296
 
296
297
  if entry
297
298
  get_entry_value(entry, name, options)
298
299
  else
299
300
  save_block_result_to_cache(name, options) { |_name| yield _name }
300
301
  end
302
+ elsif options && options[:force]
303
+ raise ArgumentError, 'Missing block: Calling `Cache#fetch` with `force: true` requires a block.'
301
304
  else
302
305
  read(name, options)
303
306
  end
@@ -310,7 +313,7 @@ module ActiveSupport
310
313
  # Options are passed to the underlying cache implementation.
311
314
  def read(name, options = nil)
312
315
  options = merged_options(options)
313
- key = namespaced_key(name, options)
316
+ key = normalize_key(name, options)
314
317
  instrument(:read, name, options) do |payload|
315
318
  entry = read_entry(key, options)
316
319
  if entry
@@ -329,7 +332,7 @@ module ActiveSupport
329
332
  end
330
333
  end
331
334
 
332
- # Read multiple values at once from the cache. Options can be passed
335
+ # Reads multiple values at once from the cache. Options can be passed
333
336
  # in the last argument.
334
337
  #
335
338
  # Some cache implementation may optimize this method.
@@ -338,9 +341,10 @@ module ActiveSupport
338
341
  def read_multi(*names)
339
342
  options = names.extract_options!
340
343
  options = merged_options(options)
344
+
341
345
  results = {}
342
346
  names.each do |name|
343
- key = namespaced_key(name, options)
347
+ key = normalize_key(name, options)
344
348
  entry = read_entry(key, options)
345
349
  if entry
346
350
  if entry.expired?
@@ -363,8 +367,11 @@ module ActiveSupport
363
367
  # Returns a hash with the data for each of the names. For example:
364
368
  #
365
369
  # cache.write("bim", "bam")
366
- # cache.fetch_multi("bim", "boom") { |key| key * 2 }
367
- # # => { "bam" => "bam", "boom" => "boomboom" }
370
+ # cache.fetch_multi("bim", "unknown_key") do |key|
371
+ # "Fallback value for key: #{key}"
372
+ # end
373
+ # # => { "bim" => "bam",
374
+ # # "unknown_key" => "Fallback value for key: unknown_key" }
368
375
  #
369
376
  def fetch_multi(*names)
370
377
  options = names.extract_options!
@@ -388,7 +395,7 @@ module ActiveSupport
388
395
 
389
396
  instrument(:write, name, options) do
390
397
  entry = Entry.new(value, options)
391
- write_entry(namespaced_key(name, options), entry, options)
398
+ write_entry(normalize_key(name, options), entry, options)
392
399
  end
393
400
  end
394
401
 
@@ -399,7 +406,7 @@ module ActiveSupport
399
406
  options = merged_options(options)
400
407
 
401
408
  instrument(:delete, name) do
402
- delete_entry(namespaced_key(name, options), options)
409
+ delete_entry(normalize_key(name, options), options)
403
410
  end
404
411
  end
405
412
 
@@ -410,12 +417,12 @@ module ActiveSupport
410
417
  options = merged_options(options)
411
418
 
412
419
  instrument(:exist?, name) do
413
- entry = read_entry(namespaced_key(name, options), options)
420
+ entry = read_entry(normalize_key(name, options), options)
414
421
  (entry && !entry.expired?) || false
415
422
  end
416
423
  end
417
424
 
418
- # Delete all entries with keys matching the pattern.
425
+ # Deletes all entries with keys matching the pattern.
419
426
  #
420
427
  # Options are passed to the underlying cache implementation.
421
428
  #
@@ -424,7 +431,7 @@ module ActiveSupport
424
431
  raise NotImplementedError.new("#{self.class.name} does not support delete_matched")
425
432
  end
426
433
 
427
- # Increment an integer value in the cache.
434
+ # Increments an integer value in the cache.
428
435
  #
429
436
  # Options are passed to the underlying cache implementation.
430
437
  #
@@ -433,7 +440,7 @@ module ActiveSupport
433
440
  raise NotImplementedError.new("#{self.class.name} does not support increment")
434
441
  end
435
442
 
436
- # Decrement an integer value in the cache.
443
+ # Decrements an integer value in the cache.
437
444
  #
438
445
  # Options are passed to the underlying cache implementation.
439
446
  #
@@ -442,7 +449,7 @@ module ActiveSupport
442
449
  raise NotImplementedError.new("#{self.class.name} does not support decrement")
443
450
  end
444
451
 
445
- # Cleanup the cache by removing expired entries.
452
+ # Cleanups the cache by removing expired entries.
446
453
  #
447
454
  # Options are passed to the underlying cache implementation.
448
455
  #
@@ -451,7 +458,7 @@ module ActiveSupport
451
458
  raise NotImplementedError.new("#{self.class.name} does not support cleanup")
452
459
  end
453
460
 
454
- # Clear the entire cache. Be careful with this method since it could
461
+ # Clears the entire cache. Be careful with this method since it could
455
462
  # affect other processes if shared cache is being used.
456
463
  #
457
464
  # The options hash is passed to the underlying cache implementation.
@@ -462,7 +469,7 @@ module ActiveSupport
462
469
  end
463
470
 
464
471
  protected
465
- # Add the namespace defined in the options to a pattern designed to
472
+ # Adds the namespace defined in the options to a pattern designed to
466
473
  # match keys. Implementations that support delete_matched should call
467
474
  # this method to translate a pattern that matches names into one that
468
475
  # matches namespaced keys.
@@ -481,26 +488,26 @@ module ActiveSupport
481
488
  end
482
489
  end
483
490
 
484
- # Read an entry from the cache implementation. Subclasses must implement
491
+ # Reads an entry from the cache implementation. Subclasses must implement
485
492
  # this method.
486
493
  def read_entry(key, options) # :nodoc:
487
494
  raise NotImplementedError.new
488
495
  end
489
496
 
490
- # Write an entry to the cache implementation. Subclasses must implement
497
+ # Writes an entry to the cache implementation. Subclasses must implement
491
498
  # this method.
492
499
  def write_entry(key, entry, options) # :nodoc:
493
500
  raise NotImplementedError.new
494
501
  end
495
502
 
496
- # Delete an entry from the cache implementation. Subclasses must
503
+ # Deletes an entry from the cache implementation. Subclasses must
497
504
  # implement this method.
498
505
  def delete_entry(key, options) # :nodoc:
499
506
  raise NotImplementedError.new
500
507
  end
501
508
 
502
509
  private
503
- # Merge the default options with ones specific to a method call.
510
+ # Merges the default options with ones specific to a method call.
504
511
  def merged_options(call_options) # :nodoc:
505
512
  if call_options
506
513
  options.merge(call_options)
@@ -509,7 +516,7 @@ module ActiveSupport
509
516
  end
510
517
  end
511
518
 
512
- # Expand key to be a consistent string value. Invoke +cache_key+ if
519
+ # Expands key to be a consistent string value. Invokes +cache_key+ if
513
520
  # object responds to +cache_key+. Otherwise, +to_param+ method will be
514
521
  # called. If the key is a Hash, then keys will be sorted alphabetically.
515
522
  def expanded_key(key) # :nodoc:
@@ -529,9 +536,9 @@ module ActiveSupport
529
536
  key.to_param
530
537
  end
531
538
 
532
- # Prefix a key with the namespace. Namespace and key will be delimited
539
+ # Prefixes a key with the namespace. Namespace and key will be delimited
533
540
  # with a colon.
534
- def namespaced_key(key, options)
541
+ def normalize_key(key, options)
535
542
  key = expanded_key(key)
536
543
  namespace = options[:namespace] if options
537
544
  prefix = namespace.is_a?(Proc) ? namespace.call : namespace
@@ -539,32 +546,33 @@ module ActiveSupport
539
546
  key
540
547
  end
541
548
 
549
+ def namespaced_key(*args)
550
+ ActiveSupport::Deprecation.warn(<<-MESSAGE.strip_heredoc)
551
+ `namespaced_key` is deprecated and will be removed from Rails 5.1.
552
+ Please use `normalize_key` which will return a fully resolved key.
553
+ MESSAGE
554
+ normalize_key(*args)
555
+ end
556
+
542
557
  def instrument(operation, key, options = nil)
543
- log(operation, key, options)
558
+ log { "Cache #{operation}: #{normalize_key(key, options)}#{options.blank? ? "" : " (#{options.inspect})"}" }
544
559
 
545
560
  payload = { :key => key }
546
561
  payload.merge!(options) if options.is_a?(Hash)
547
562
  ActiveSupport::Notifications.instrument("cache_#{operation}.active_support", payload){ yield(payload) }
548
563
  end
549
564
 
550
- def log(operation, key, options = nil)
565
+ def log
551
566
  return unless logger && logger.debug? && !silence?
552
- logger.debug("Cache #{operation}: #{key}#{options.blank? ? "" : " (#{options.inspect})"}")
553
- end
554
-
555
- def find_cached_entry(key, name, options)
556
- instrument(:read, name, options) do |payload|
557
- payload[:super_operation] = :fetch if payload
558
- read_entry(key, options)
559
- end
567
+ logger.debug(yield)
560
568
  end
561
569
 
562
570
  def handle_expired_entry(entry, key, options)
563
571
  if entry && entry.expired?
564
572
  race_ttl = options[:race_condition_ttl].to_i
565
- if race_ttl && (Time.now.to_f - entry.expires_at <= race_ttl)
566
- # When an entry has :race_condition_ttl defined, put the stale entry back into the cache
567
- # for a brief period while the entry is begin recalculated.
573
+ if (race_ttl > 0) && (Time.now.to_f - entry.expires_at <= race_ttl)
574
+ # When an entry has a positive :race_condition_ttl defined, put the stale entry back into the cache
575
+ # for a brief period while the entry is being recalculated.
568
576
  entry.expires_at = Time.now + race_ttl
569
577
  write_entry(key, entry, :expires_in => race_ttl * 2)
570
578
  else
@@ -576,12 +584,12 @@ module ActiveSupport
576
584
  end
577
585
 
578
586
  def get_entry_value(entry, name, options)
579
- instrument(:fetch_hit, name, options) { |payload| }
587
+ instrument(:fetch_hit, name, options) { }
580
588
  entry.value
581
589
  end
582
590
 
583
591
  def save_block_result_to_cache(name, options)
584
- result = instrument(:generate, name, options) do |payload|
592
+ result = instrument(:generate, name, options) do
585
593
  yield(name)
586
594
  end
587
595
 
@@ -599,7 +607,7 @@ module ActiveSupport
599
607
  class Entry # :nodoc:
600
608
  DEFAULT_COMPRESS_LIMIT = 16.kilobytes
601
609
 
602
- # Create a new cache entry for the specified value. Options supported are
610
+ # Creates a new cache entry for the specified value. Options supported are
603
611
  # +:compress+, +:compress_threshold+, and +:expires_in+.
604
612
  def initialize(value, options = {})
605
613
  if should_compress?(value, options)
@@ -615,14 +623,12 @@ module ActiveSupport
615
623
  end
616
624
 
617
625
  def value
618
- convert_version_4beta1_entry! if defined?(@v)
619
626
  compressed? ? uncompress(@value) : @value
620
627
  end
621
628
 
622
- # Check if the entry is expired. The +expires_in+ parameter can override
629
+ # Checks if the entry is expired. The +expires_in+ parameter can override
623
630
  # the value set when the entry was created.
624
631
  def expired?
625
- convert_version_4beta1_entry! if defined?(@value)
626
632
  @expires_in && @created_at + @expires_in <= Time.now.to_f
627
633
  end
628
634
 
@@ -655,11 +661,9 @@ module ActiveSupport
655
661
  end
656
662
  end
657
663
 
658
- # Duplicate the value in a class. This is used by cache implementations that don't natively
664
+ # Duplicates the value in a class. This is used by cache implementations that don't natively
659
665
  # serialize entries to protect against accidental cache modifications.
660
666
  def dup_value!
661
- convert_version_4beta1_entry! if defined?(@v)
662
-
663
667
  if @value && !compressed? && !(@value.is_a?(Numeric) || @value == true || @value == false)
664
668
  if @value.is_a?(String)
665
669
  @value = @value.dup
@@ -692,26 +696,6 @@ module ActiveSupport
692
696
  def uncompress(value)
693
697
  Marshal.load(Zlib::Inflate.inflate(value))
694
698
  end
695
-
696
- # The internals of this method changed between Rails 3.x and 4.0. This method provides the glue
697
- # to ensure that cache entries created under the old version still work with the new class definition.
698
- def convert_version_4beta1_entry!
699
- if defined?(@v)
700
- @value = @v
701
- remove_instance_variable(:@v)
702
- end
703
-
704
- if defined?(@c)
705
- @compressed = @c
706
- remove_instance_variable(:@c)
707
- end
708
-
709
- if defined?(@x) && @x
710
- @created_at ||= Time.now.to_f
711
- @expires_in = @x - @created_at
712
- remove_instance_variable(:@x)
713
- end
714
- end
715
699
  end
716
700
  end
717
701
  end