Skip to content

Instantly share code, notes, and snippets.

@sreeix
Created May 9, 2011 08:11
Show Gist options
  • Save sreeix/962221 to your computer and use it in GitHub Desktop.
Save sreeix/962221 to your computer and use it in GitHub Desktop.
Around wrapper to do simple memcached peruser
module CachingHelper
def self.included(claz)
claz.extend ClassMethods
end
module ClassMethods
def sf_cache(wrapped_method)
send(:around_filter, :cache_result)
end
end
def cache_result
key = "#{current_user.id}:#{request.url}"
if(page = Cache.get(key))
Rails.logger.debug("CACHE HIT: for #{key}")
response.body = page
response.status = 200
response.content_type = :xml
else
yield
if(request.get? && response.status == "200 OK")
Rails.logger.debug("CACHE MISS: setting into memcached #{response.body}" )
Cache.set(key, response.body)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment