Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Better way to caching.

  • Loading branch information...
commit fb4e9f99afdacdd40627fd3c196997a61ed92cd8 1 parent c644c3f
@DAddYE DAddYE authored
Showing with 19 additions and 0 deletions.
  1. +19 −0 lib/caching.rb
View
19 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)
Please sign in to comment.
Something went wrong with that request. Please try again.