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:
Rafael Mendonça França
2013-09-12 11:32:45 -07:00
parent c9642e31b1
commit c539c684aa
3 changed files with 18 additions and 1 deletions

View File

@@ -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.

View File

@@ -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

View File

@@ -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