Skip to content

Instantly share code, notes, and snippets.

@bastos
Created October 16, 2008 13:55
Show Gist options
  • Save bastos/17138 to your computer and use it in GitHub Desktop.
Save bastos/17138 to your computer and use it in GitHub Desktop.
line 16 just for debbug, remove it later!
# 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