Skip to content

Commit

Permalink
Remove LRUCache instance
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasleese committed Aug 23, 2018
1 parent c84a024 commit 5c239d0
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 32 deletions.
1 change: 0 additions & 1 deletion gds-api-adapters.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.add_dependency 'addressable'
s.add_dependency 'link_header'
s.add_dependency 'lrucache', '~> 0.1.1'
s.add_dependency 'null_logger'
s.add_dependency 'plek', '>= 1.9.0'
s.add_dependency 'rack-cache'
Expand Down
14 changes: 1 addition & 13 deletions lib/gds_api/json_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,14 @@
require_relative 'version'
require_relative 'null_cache'
require_relative 'govuk_headers'
require 'lrucache'
require 'rest-client'
require 'null_logger'

module GdsApi
class JsonClient
include GdsApi::ExceptionHandling

# Cache TTL will be overridden for a given request/response by the Expires
# header if it is included in the response.
#
# LRUCache doesn't respect a cache size of 0, and instead effectively
# creates a cache with a size of 1.
def self.cache(size = DEFAULT_CACHE_SIZE, ttl = DEFAULT_CACHE_TTL)
@cache ||= LRUCache.new(max_size: size, ttl: ttl)
end

# Set the caching implementation. Default is LRUCache. Can be Anything
# Set the caching implementation. Default is Null. Can be Anything
# which responds to:
#
# [](key)
Expand Down Expand Up @@ -62,8 +52,6 @@ def self.json_body_headers
end

DEFAULT_TIMEOUT_IN_SECONDS = 4
DEFAULT_CACHE_SIZE = 100
DEFAULT_CACHE_TTL = 15 * 60 # 15 minutes

def get_raw!(url)
do_raw_request(:get, url)
Expand Down
5 changes: 0 additions & 5 deletions test/gds_api_base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ def base_url
end
end

def setup
@orig_cache = GdsApi::JsonClient.cache
end

def teardown
GdsApi::Base.default_options = nil
GdsApi::JsonClient.cache = @orig_cache
end

def test_should_construct_escaped_query_string
Expand Down
13 changes: 0 additions & 13 deletions test/json_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,11 @@

class JsonClientTest < MiniTest::Spec
def setup
@json_client_cache = GdsApi::JsonClient.cache

# Set the cache to nil so the JsonClient recreates it on each test run
# This used to initialise the cache to an empty Hash, eliminating the
# potential problem of cache entries expiring during a test run, but that
# no longer works now our code calls the `store` method with an expiry time
GdsApi::JsonClient.cache = nil

@client = GdsApi::JsonClient.new

WebMock.disable_net_connect!
end

def teardown
super
GdsApi::JsonClient.cache = @json_client_cache
end

def options;
{}
end
Expand Down

0 comments on commit 5c239d0

Please sign in to comment.