Created
August 17, 2012 23:01
-
-
Save teeparham/3383344 to your computer and use it in GitHub Desktop.
Patch for nanosecond cache_key precision for Rails 3.x
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
# see https://github.com/rails/rails/pull/6376 | |
# put this in an initializer | |
module NsecCacheKeyPatch | |
# Override ActiveRecord::Integration#cache_key | |
def cache_key | |
case | |
when new_record? | |
"#{self.class.model_name.cache_key}/new" | |
when timestamp = self[:updated_at] | |
timestamp = timestamp.utc.to_s(:nsec) | |
"#{self.class.model_name.cache_key}/#{id}-#{timestamp}" | |
else | |
"#{self.class.model_name.cache_key}/#{id}" | |
end | |
end | |
end | |
::Time::DATE_FORMATS[:nsec] = '%Y%m%d%H%M%S%9N' | |
ActiveRecord::Base.send :include, NsecCacheKeyPatch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment