aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-10-25 22:22:43 +0200
committerJosé Valim <jose.valim@gmail.com>2011-10-25 22:23:25 +0200
commit771ca79f74db1e5a19703ad92472515dbebb70c7 (patch)
tree305ea727831e5d72fedcee48349946388e08c050
parent2856d74db74df4fb4cf01b62861f59343155ec64 (diff)
downloadrails-771ca79f74db1e5a19703ad92472515dbebb70c7.tar.gz
rails-771ca79f74db1e5a19703ad92472515dbebb70c7.tar.bz2
rails-771ca79f74db1e5a19703ad92472515dbebb70c7.zip
Revert "Merge pull request #3395 from bdurand/fix_file_store_cleanup"
Tests were failing on Travis-CI. This reverts commit 79d01a8f16e20c556a086a2f07e3ccb4400f9819, reversing changes made to b838570bd69ff13d677fb43e79f10d6f3168c696.
-rw-r--r--activesupport/lib/active_support/cache/file_store.rb21
-rw-r--r--activesupport/test/caching_test.rb34
-rw-r--r--railties/guides/source/caching_with_rails.textile6
3 files changed, 4 insertions, 57 deletions
diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb
index bc5d94b5a7..b431041b76 100644
--- a/activesupport/lib/active_support/cache/file_store.rb
+++ b/activesupport/lib/active_support/cache/file_store.rb
@@ -26,26 +26,11 @@ module ActiveSupport
FileUtils.rm_r(root_dirs.collect{|f| File.join(cache_path, f)})
end
- # Cleanup the cache by removing old entries. By default this will delete entries
- # that haven't been accessed in one day. You can change this behavior by passing
- # in a +not_accessed_in+ option. Any entry not accessed in that number of seconds
- # in the past will be deleted. Alternatively, you can pass in +:expired_only+ with
- # +true+ to only delete expired entries.
def cleanup(options = nil)
options = merged_options(options)
- expired_only = options[:expired_only]
- timestamp = Time.now - (options[:not_accessed_in] || 1.day.to_i)
- search_dir(cache_path) do |fname|
- if expired_only
- key = file_path_key(fname)
- entry = read_entry(key, options)
- delete_entry(key, options) if entry && entry.expired?
- else
- if File.atime(fname) <= timestamp
- key = file_path_key(fname)
- delete_entry(key, options)
- end
- end
+ each_key(options) do |key|
+ entry = read_entry(key, options)
+ delete_entry(key, options) if entry && entry.expired?
end
end
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index 1b2f6d061c..cb5362525f 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -557,29 +557,6 @@ class FileStoreTest < ActiveSupport::TestCase
key = @cache_with_pathname.send(:key_file_path, "views/index?id=1")
assert_equal "views/index?id=1", @cache_with_pathname.send(:file_path_key, key)
end
-
- def test_cleanup_with_not_accessed_in
- @cache.write(1, "aaaaaaaaaa")
- @cache.write(2, "bbbbbbbbbb")
- @cache.write(3, "cccccccccc")
- sleep(2)
- @cache.read(2)
- @cache.cleanup(:not_accessed_in => 1)
- assert_equal false, @cache.exist?(1)
- assert_equal true, @cache.exist?(2)
- assert_equal false, @cache.exist?(3)
- end
-
- def test_cleanup_with_expired_only
- @cache.write(1, "aaaaaaaaaa", :expires_in => 0.001)
- @cache.write(2, "bbbbbbbbbb")
- @cache.write(3, "cccccccccc", :expires_in => 0.001)
- sleep(0.002)
- @cache.cleanup(:expired_only => 0.001)
- assert_equal false, @cache.exist?(1)
- assert_equal true, @cache.exist?(2)
- assert_equal false, @cache.exist?(3)
- end
# Because file systems have a maximum filename size, filenames > max size should be split in to directories
# If filename is 'AAAAB', where max size is 4, the returned path should be AAAA/B
@@ -669,17 +646,6 @@ class MemoryStoreTest < ActiveSupport::TestCase
assert_equal true, @cache.exist?(2)
assert_equal false, @cache.exist?(1)
end
-
- def test_cleanup_removes_expired_entries
- @cache.write(1, "aaaaaaaaaa", :expires_in => 0.001)
- @cache.write(2, "bbbbbbbbbb")
- @cache.write(3, "cccccccccc", :expires_in => 0.001)
- sleep(0.002)
- @cache.cleanup
- assert_equal false, @cache.exist?(1)
- assert_equal true, @cache.exist?(2)
- assert_equal false, @cache.exist?(3)
- end
end
uses_memcached 'memcached backed store' do
diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile
index 721c791a33..4273d0dd64 100644
--- a/railties/guides/source/caching_with_rails.textile
+++ b/railties/guides/source/caching_with_rails.textile
@@ -289,11 +289,7 @@ ActionController::Base.cache_store = :file_store, "/path/to/cache/directory"
With this cache store, multiple server processes on the same host can share a cache. Servers processes running on different hosts could share a cache by using a shared file system, but that set up would not be ideal and is not recommended. The cache store is appropriate for low to medium traffic sites that are served off one or two hosts.
-Note that the cache will grow until the disk is full unless you periodically clear out old entries. You can call +ActiveSupport::Cache::FileStore#cleanup+ to remove entries older than a specified time.
-
-<ruby>
-Rails.cache.cleanup(:not_accessed_in => 2.days)
-</ruby>
+Note that the cache will grow until the disk is full unless you periodically clear out old entries.
h4. ActiveSupport::Cache::MemCacheStore