Permalink
Browse files

Cache response with request tokens

  • Loading branch information...
rosylilly committed Oct 31, 2015
1 parent 239e7c7 commit 67be1ef32fd0d6a56f2b56184359566c12912ac2
Showing with 7 additions and 2 deletions.
  1. +7 −2 5f/webapp/ruby/app.rb
View
@@ -82,7 +82,8 @@ def self.get(name)
def initialize(name, method, token_type, token_key, uri, mode = :http)
@name, @method, @token_type, @token_key, @uri, @mode = name, method, token_type, token_key, uri, mode
@ssl = uri.start_with?('https://')
@cachable = @token_type.nil? && @method == 'GET'
@cachable = @method == 'GET'
@expirable = @token_type.nil?
LIST[@name] = self
end
@@ -100,7 +101,11 @@ def fetch_with_cache(conf, redis)
MessagePack.unpack(cached)
else
res = fetch(conf)
redis.set("api/cache/#{hash}", res.to_msgpack)
if @expirable
redis.psetex("api/cache/#{hash}", 3000, res.to_msgpack)
else
redis.set("api/cache/#{hash}", res.to_msgpack)
end
res
end
end

0 comments on commit 67be1ef

Please sign in to comment.