aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorBrian Durand <brian@embellishedvisions.com>2011-10-21 13:28:24 -0500
committerBrian Durand <brian@embellishedvisions.com>2011-10-21 13:28:24 -0500
commitec93f363cab7270c1469b420a52a21e306a89c30 (patch)
tree826b6d8351d6b254bd877fb1fa47ac927088ba4a /activesupport/lib/active_support
parente2aaae16292640f2314be205d7782f6eaf2b1cf5 (diff)
downloadrails-ec93f363cab7270c1469b420a52a21e306a89c30.tar.gz
rails-ec93f363cab7270c1469b420a52a21e306a89c30.tar.bz2
rails-ec93f363cab7270c1469b420a52a21e306a89c30.zip
Fix ActiveSupport::Cache::FileStore.cleanup to actually work.
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/cache/file_store.rb21
1 files changed, 18 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb
index b431041b76..bc5d94b5a7 100644
--- a/activesupport/lib/active_support/cache/file_store.rb
+++ b/activesupport/lib/active_support/cache/file_store.rb
@@ -26,11 +26,26 @@ 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)
- each_key(options) do |key|
- entry = read_entry(key, options)
- delete_entry(key, options) if entry && entry.expired?
+ 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
end
end