Skip to content

Commit

Permalink
Fixed cache ttl.
Browse files Browse the repository at this point in the history
  • Loading branch information
intinig committed Apr 4, 2014
1 parent 14b2d53 commit ad61a81
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
5 changes: 1 addition & 4 deletions lib/lol/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ def perform_request url
raise NotFound.new("404 Not Found") if response.respond_to?(:code) && response.not_found?
raise InvalidAPIResponse.new(response["status"]["message"]) if response.is_a?(Hash) && response["status"]

if cached?
store.set clean_url(url), response.to_json
store.expire url, ttl
end
store.setex clean_url(url), ttl, response.to_json if cached?

response
end
Expand Down
2 changes: 1 addition & 1 deletion lib/lol/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Lol
VERSION = "0.9.13"
VERSION = "0.9.14"
end
8 changes: 3 additions & 5 deletions spec/lol/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
context "caching" do
before :all do
class FakeRedis < Redis
attr_reader :store

def initialize options = {}
@store = {}
end
Expand All @@ -62,11 +64,8 @@ def get key
@store[key]
end

def set key, val
def setex key, ttl, val
@store[key] = val
end

def expire key, ttl
@store["#{key}:ttl"] = ttl
end
end
Expand All @@ -82,7 +81,6 @@ def expire key, ttl
it "is cached" do
expect(request.class).not_to receive(:get)
request.perform_request "/foo"

end

it "serializes cached responses" do
Expand Down

0 comments on commit ad61a81

Please sign in to comment.