Skip to content

Instantly share code, notes, and snippets.

View svyatogor's full-sized avatar

Sergey Kuleshov svyatogor

View GitHub Profile
@svyatogor
svyatogor / gist:988887
Created May 24, 2011 15:12
mongoid per id cache
module Mongoid #:nodoc:
module Cache
extend ActiveSupport::Concern
included do
class << self
alias_method :original_find, :find
def find_with_cache(*args)
if args.length == 1 and (args[0].is_a? BSON::ObjectId or args[0].is_a? String)
Rails.cache.fetch("#{self.name}::#{args[0].to_s}") {find_without_cache *args}