Created
November 11, 2009 22:29
-
-
Save mhorbul/232378 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Author: Maksim Horbul | |
| # | |
| # This patch allows to use :expires_in option with the FileStore Cache | |
| # | |
| # Example: | |
| # <% cache :expires_in => 10.minutes %> | |
| # <div>Cool fragment which is going to be expired in 10 minutes.</div> | |
| # <% end %> | |
| # | |
| module ActiveSupport | |
| module Cache | |
| class FileStore < Store | |
| def read_with_expiration(name, options = nil) | |
| expired?(name, options) ? nil : read_without_expiration(name, options) | |
| end | |
| alias_method_chain :read, :expiration | |
| private | |
| def expired?(name, options = {}) | |
| _expired_at = expires_at(name, options) | |
| _expired_at ? _expired_at < Time.now : false | |
| end | |
| def expires_at(name, options = {}) | |
| _expires_in = expires_in(options) | |
| if _expires_in > 0 | |
| File.stat(real_file_path(name)).ctime + _expires_in rescue nil | |
| end | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment