diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-06-23 18:13:46 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-06-23 18:13:46 -0300 |
commit | b9088dce07f8525cdb84a1312a77b81db79067d6 (patch) | |
tree | 72ace069842b074981ba814ef1c335271176ce27 /activesupport/lib/active_support/cache/file_store.rb | |
parent | 4864f92ee34e840307d968fa8b04972b6d786fe8 (diff) | |
parent | 4417a19b035d73eb46a5e06e296a4b1c8091bef1 (diff) | |
download | rails-b9088dce07f8525cdb84a1312a77b81db79067d6.tar.gz rails-b9088dce07f8525cdb84a1312a77b81db79067d6.tar.bz2 rails-b9088dce07f8525cdb84a1312a77b81db79067d6.zip |
Merge commit 'rails/master'
Diffstat (limited to 'activesupport/lib/active_support/cache/file_store.rb')
-rw-r--r-- | activesupport/lib/active_support/cache/file_store.rb | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb index 3217350d58..75eed5ed94 100644 --- a/activesupport/lib/active_support/cache/file_store.rb +++ b/activesupport/lib/active_support/cache/file_store.rb @@ -10,11 +10,23 @@ module ActiveSupport @cache_path = cache_path end + # Reads a value from the cache. + # + # Possible options: + # - +:expires_in+ - the number of seconds that this value may stay in + # the cache. def read(name, options = nil) super - File.open(real_file_path(name), 'rb') { |f| Marshal.load(f) } rescue nil + + file_name = real_file_path(name) + expires = expires_in(options) + + if File.exist?(file_name) && (expires <= 0 || Time.now - File.mtime(file_name) < expires) + File.open(file_name, 'rb') { |f| Marshal.load(f) } + end end + # Writes a value to the cache. def write(name, value, options = nil) super ensure_cache_path(File.dirname(real_file_path(name))) |