Last active
December 16, 2015 23:59
-
-
Save tkosuga/5517667 to your computer and use it in GitHub Desktop.
lib/flickraw/api.rbをlib/flickraw/api_ext.rbな感じでcache。キャッシュ先でMarshal.dump/loadしてます。
This file contains 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
# lib/flickraw/api.rb | |
def call(req, args={}, &block) | |
rest_path = FlickRaw.secure ? REST_PATH_SECURE : REST_PATH | |
http_response = @oauth_consumer.post_form(rest_path, @access_secret, {:oauth_token => @access_token}, build_args(args, req)) | |
process_response(req, http_response.body) | |
end | |
This file contains 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
# lib/flickraw/api.rb | |
def cache_key(req, args) | |
URI.encode((req + args.to_s).gsub(/[\s\t=>'",\{\}]/, "/").gsub(/\/+/, "/")) | |
end | |
def call(req, args={}, &block) | |
cache_key = cache_key(req, args) | |
result = CacheServer.instance.get(cache_key) | |
if result.blank? | |
rest_path = FlickRaw.secure ? REST_PATH_SECURE : REST_PATH | |
http_response = @oauth_consumer.post_form(rest_path, @access_secret, {:oauth_token => @access_token}, build_args(args, req)) | |
result = process_response(req, http_response.body) | |
CacheServer.instance.push(cache_key, result) | |
end | |
result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment