Created
October 16, 2008 13:55
-
-
Save bastos/17138 to your computer and use it in GitHub Desktop.
line 16 just for debbug, remove it later!
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
# Cache XML RPC calls | |
# | |
# Author:: Tiago Bastos (mailto:[email protected]). | |
# Copyright:: Copyright 2008 Laverock von Schoultz, Gibraltar | |
class XMLRPCCachedClient < XMLRPC::Client | |
def call(method, *args) | |
if ActionController::Base.perform_caching | |
# Generate unique ley using method and argumets | |
key = "xmlrpc:call:" + Digest::MD5.hexdigest("#{method}:#{args.to_s}") | |
cached = CACHE.get(key) | |
# If there is no cache, get data from API | |
if cached.nil? | |
RAILS_DEFAULT_LOGGER.info "CACHE ADD#{key} #{method}:#{args.to_s}" | |
result = super | |
RAILS_DEFAULT_LOGGER.info "CACHE SIZE OF #{key} #{method} SIZE: #{Marshal.dump(result).size} bytes" | |
CACHE.set(key, result, 10) | |
return result | |
else | |
# If not return cache | |
RAILS_DEFAULT_LOGGER.info "CACHE GET #{key} #{method}:#{args.to_s}" | |
cached | |
end | |
else | |
super | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment