mirror of
https://github.com/github/rails.git
synced 2026-01-10 07:07:54 -05:00
Merge pull request #12196 from h-lame/fix-activesupport-cache-filestore-cleanup
Fix FileStore#cleanup to no longer rely on missing each_key method Conflicts: activesupport/CHANGELOG.md activesupport/test/caching_test.rb
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
## unreleased ##
|
||||
|
||||
* Fix ActiveSupport::Cache::FileStore#cleanup to no longer rely on missing each_key method.
|
||||
|
||||
*Murray Steele*
|
||||
|
||||
* Add respond_to_missing? for TaggedLogging which is best practice when overriding method_missing. This permits
|
||||
wrapping TaggedLogging by another log abstraction such as em-logger.
|
||||
|
||||
|
||||
@@ -29,7 +29,8 @@ module ActiveSupport
|
||||
|
||||
def cleanup(options = nil)
|
||||
options = merged_options(options)
|
||||
each_key(options) do |key|
|
||||
search_dir(cache_path) do |fname|
|
||||
key = file_path_key(fname)
|
||||
entry = read_entry(key, options)
|
||||
delete_entry(key, options) if entry && entry.expired?
|
||||
end
|
||||
|
||||
@@ -608,6 +608,18 @@ class FileStoreTest < ActiveSupport::TestCase
|
||||
ActiveSupport::Cache::FileStore.new('/test/cache/directory').delete_matched(/does_not_exist/)
|
||||
end
|
||||
end
|
||||
|
||||
def test_cleanup_removes_all_expired_entries
|
||||
time = Time.now
|
||||
@cache.write('foo', 'bar', expires_in: 10)
|
||||
@cache.write('baz', 'qux')
|
||||
@cache.write('quux', 'corge', expires_in: 20)
|
||||
Time.stubs(:now).returns(time + 15)
|
||||
@cache.cleanup
|
||||
assert !@cache.exist?('foo')
|
||||
assert @cache.exist?('baz')
|
||||
assert @cache.exist?('quux')
|
||||
end
|
||||
end
|
||||
|
||||
class MemoryStoreTest < ActiveSupport::TestCase
|
||||
|
||||
Reference in New Issue
Block a user