From accd4926cc072217bc98b82368d20fb8f79a8bca Mon Sep 17 00:00:00 2001 From: Murray Steele Date: Wed, 11 Sep 2013 13:24:50 +0100 Subject: Fix FileStore#cleanup to no longer rely on missing each_key method --- activesupport/CHANGELOG.md | 4 ++++ activesupport/lib/active_support/cache/file_store.rb | 3 ++- activesupport/test/caching_test.rb | 12 ++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index f15297f279..44d0fb2fea 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,7 @@ +* Fix ActiveSupport::Cache::FileStore#cleanup to no longer rely on missing each_key method. + + *Murray Steele* + * Ensure that autoloaded constants in all-caps nestings are marked as autoloaded. diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb index 472f23c1c5..10d39463ec 100644 --- a/activesupport/lib/active_support/cache/file_store.rb +++ b/activesupport/lib/active_support/cache/file_store.rb @@ -33,7 +33,8 @@ module ActiveSupport # Premptively iterates through all stored keys and removes the ones which have expired. 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 diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index df570d485a..16d087ab9d 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -709,6 +709,18 @@ class FileStoreTest < ActiveSupport::TestCase @cache.send(:read_entry, "winston", {}) assert @buffer.string.present? 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_not @cache.exist?('foo') + assert @cache.exist?('baz') + assert @cache.exist?('quux') + end end class MemoryStoreTest < ActiveSupport::TestCase -- cgit v1.2.3