Skip to content

Commit

Permalink
Better way to caching.
Browse files Browse the repository at this point in the history
  • Loading branch information
DAddYE committed May 11, 2011
1 parent c644c3f commit fb4e9f9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/caching.rb
@@ -0,0 +1,19 @@
module Caching
extend ActiveSupport::Concern

module InstanceMethods
def cache_key(*suffixes)
cache_key = case
when !persisted?
"#{self.class.name.downcase}-new"
when timestamp = self[:updated_at]
"#{self.class.name.downcase}-#{id}-#{timestamp.to_s(:number)}"
else
"#{self.class.name.downcase}-#{id}"
end
cache_key += "#{suffixes.join('-')}" unless suffixes.empty?
cache_key
end
end # InstanceMethods
end # Caching
MongoMapper::Document.send(:include, Caching)

0 comments on commit fb4e9f9

Please sign in to comment.