Skip to content

Commit a8f773b

Browse files
committed
add deprecations for a smooth transition after #22215
1 parent 3d8a7c0 commit a8f773b

File tree

6 files changed

+72
-4
lines changed

6 files changed

+72
-4
lines changed

Diff for: activesupport/CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
* `ActiveSupport::Cache::Store#namespaced_key`,
2+
`ActiveSupport::Cache::MemCachedStore#escape_key`, and
3+
`ActiveSupport::Cache::FileStore#key_file_path`
4+
are deprecated and replaced with `normalize_key` that now calls `super`.
5+
6+
`ActiveSupport::Cache::LocaleCache#set_cache_value` is deprecated and replaced with `write_cache_value`.
7+
8+
*Michael Grosser*
9+
110
* Implements an evented file system monitor to asynchronously detect changes
211
in the application source code, routes, locales, etc.
312

Diff for: activesupport/lib/active_support/cache.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
require 'active_support/core_ext/numeric/time'
99
require 'active_support/core_ext/object/to_param'
1010
require 'active_support/core_ext/string/inflections'
11+
require 'active_support/core_ext/string/strip'
1112

1213
module ActiveSupport
1314
# See ActiveSupport::Cache::Store for documentation.
@@ -536,7 +537,14 @@ def normalize_key(key, options)
536537
key = "#{prefix}:#{key}" if prefix
537538
key
538539
end
539-
alias namespaced_key normalize_key
540+
541+
def namespaced_key(*args)
542+
ActiveSupport::Deprecation.warn(<<-MESSAGE.strip_heredoc)
543+
`namespaced_key` is deprecated and will be removed from Rails 5.1.
544+
Please use `normalize_key` which will return a fully resolved key.
545+
MESSAGE
546+
normalize_key(*args)
547+
end
540548

541549
def instrument(operation, key, options = nil)
542550
log { "Cache #{operation}: #{normalize_key(key, options)}#{options.blank? ? "" : " (#{options.inspect})"}" }

Diff for: activesupport/lib/active_support/cache/file_store.rb

+8
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ def normalize_key(key, options)
137137
File.join(cache_path, DIR_FORMATTER % dir_1, DIR_FORMATTER % dir_2, *fname_paths)
138138
end
139139

140+
def key_file_path(key)
141+
ActiveSupport::Deprecation.warn(<<-MESSAGE.strip_heredoc)
142+
`key_file_path` is deprecated and will be removed from Rails 5.1.
143+
Please use `normalize_key` which will return a fully resolved key or nothing.
144+
MESSAGE
145+
key
146+
end
147+
140148
# Translate a file path into a key.
141149
def file_path_key(path)
142150
fname = path[cache_path.to_s.size..-1].split(File::SEPARATOR, 4).last

Diff for: activesupport/lib/active_support/cache/mem_cache_store.rb

+8
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ def normalize_key(key, options)
195195
key
196196
end
197197

198+
def escape_key(key)
199+
ActiveSupport::Deprecation.warn(<<-MESSAGE.strip_heredoc)
200+
`escape_key` is deprecated and will be removed from Rails 5.1.
201+
Please use `normalize_key` which will return a fully resolved key or nothing.
202+
MESSAGE
203+
key
204+
end
205+
198206
def deserialize_entry(raw_value)
199207
if raw_value
200208
entry = Marshal.load(raw_value) rescue raw_value

Diff for: activesupport/lib/active_support/cache/strategy/local_cache.rb

+11-3
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ def cleanup(options = nil) # :nodoc:
9393
def increment(name, amount = 1, options = nil) # :nodoc:
9494
return super unless local_cache
9595
value = bypass_local_cache{super}
96-
set_cache_value(name, value, options)
96+
write_cache_value(name, value, options)
9797
value
9898
end
9999

100100
def decrement(name, amount = 1, options = nil) # :nodoc:
101101
return super unless local_cache
102102
value = bypass_local_cache{super}
103-
set_cache_value(name, value, options)
103+
write_cache_value(name, value, options)
104104
value
105105
end
106106

@@ -123,7 +123,15 @@ def delete_entry(key, options) # :nodoc:
123123
super
124124
end
125125

126-
def set_cache_value(name, value, options) # :nodoc:
126+
def set_cache_value(value, name, amount, options) # :nodoc:
127+
ActiveSupport::Deprecation.warn(<<-MESSAGE.strip_heredoc)
128+
`set_cache_value` is deprecated and will be removed from Rails 5.1.
129+
Please use `write_cache_value`
130+
MESSAGE
131+
write_cache_value name, value, options
132+
end
133+
134+
def write_cache_value(name, value, options) # :nodoc:
127135
name = normalize_key(name, options)
128136
cache = local_cache
129137
cache.mute do

Diff for: activesupport/test/caching_test.rb

+27
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,12 @@ def test_cache_miss_instrumentation
518518
ensure
519519
ActiveSupport::Notifications.unsubscribe "cache_read.active_support"
520520
end
521+
522+
def test_can_call_deprecated_namesaced_key
523+
assert_deprecated "`namespaced_key` is deprecated" do
524+
@cache.send(:namespaced_key, 111, {})
525+
end
526+
end
521527
end
522528

523529
# https://rails.lighthouseapp.com/projects/8994/tickets/6225-memcachestore-cant-deal-with-umlauts-and-special-characters
@@ -693,6 +699,15 @@ def test_middleware
693699
app = @cache.middleware.new(app)
694700
app.call({})
695701
end
702+
703+
def test_can_call_deprecated_set_cache_value
704+
@cache.with_local_cache do
705+
assert_deprecated "`set_cache_value` is deprecated" do
706+
@cache.send(:set_cache_value, 1, 'foo', :ignored, {})
707+
end
708+
assert_equal 1, @cache.read('foo')
709+
end
710+
end
696711
end
697712

698713
module AutoloadingCacheBehavior
@@ -858,6 +873,12 @@ def test_write_with_unless_exist
858873
@cache.write(1, nil)
859874
assert_equal false, @cache.write(1, "aaaaaaaaaa", unless_exist: true)
860875
end
876+
877+
def test_can_call_deprecated_key_file_path
878+
assert_deprecated "`key_file_path` is deprecated" do
879+
assert_equal 111, @cache.send(:key_file_path, 111)
880+
end
881+
end
861882
end
862883

863884
class MemoryStoreTest < ActiveSupport::TestCase
@@ -1032,6 +1053,12 @@ def test_read_should_return_a_different_object_id_each_time_it_is_called
10321053
value << 'bingo'
10331054
assert_not_equal value, @cache.read('foo')
10341055
end
1056+
1057+
def test_can_call_deprecated_escape_key
1058+
assert_deprecated "`escape_key` is deprecated" do
1059+
assert_equal 111, @cache.send(:escape_key, 111)
1060+
end
1061+
end
10351062
end
10361063

10371064
class NullStoreTest < ActiveSupport::TestCase

0 commit comments

Comments
 (0)