Skip to content

Commit

Permalink
Remove NullCache class
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasleese committed Aug 23, 2018
1 parent f4d4ea0 commit 7bdc7f0
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 55 deletions.
15 changes: 1 addition & 14 deletions lib/gds_api/json_client.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require_relative 'response'
require_relative 'exceptions'
require_relative 'version'
require_relative 'null_cache'
require_relative 'govuk_headers'
require 'rest-client'
require 'null_logger'
Expand All @@ -10,26 +9,14 @@ module GdsApi
class JsonClient
include GdsApi::ExceptionHandling

# Set the caching implementation. Default is Null. Can be Anything
# which responds to:
#
# [](key)
# []=(key, value)
# store(key, value, expiry_time=nil) - or a Ruby Time object
#
class << self
attr_writer :cache
end

attr_accessor :logger, :options, :cache
attr_accessor :logger, :options

def initialize(options = {})
if options[:disable_timeout] || options[:timeout].to_i < 0
raise "It is no longer possible to disable the timeout."
end

@logger = options[:logger] || NullLogger.instance
@cache = NullCache.new
@options = options
end

Expand Down
11 changes: 0 additions & 11 deletions lib/gds_api/null_cache.rb

This file was deleted.

3 changes: 0 additions & 3 deletions lib/gds_api/test_helpers/json_client_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
require 'gds_api/json_client'
require 'gds_api/null_cache'

GdsApi::JsonClient.cache = GdsApi::NullCache.new
27 changes: 0 additions & 27 deletions test/gds_api_base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,6 @@ def test_should_accept_options_as_second_arg
assert_equal "bar", api.options[:foo]
end

def test_setting_cache_size_from_options
GdsApi::JsonClient.cache = false
api = ConcreteApi.new("https://foo", cache_size: 2)
assert api.client.cache.is_a? GdsApi::NullCache
end

def test_setting_cache_size_from_default_options
GdsApi::JsonClient.cache = false
GdsApi::Base.default_options = { cache_size: 4 }
api = ConcreteApi.new("http://bar")
assert api.client.cache.is_a? GdsApi::NullCache
end

def test_disabling_cache
# Ensure that there is a non-null cache by default
GdsApi::JsonClient.cache = true
api = ConcreteApi.new("http://bar", disable_cache: true)
assert api.client.cache.is_a? GdsApi::NullCache
end

def test_disabling_cache_old_style
# Ensure that there is a non-null cache by default
GdsApi::JsonClient.cache = true
api = ConcreteApi.new("http://bar", cache_size: 0)
assert api.client.cache.is_a? GdsApi::NullCache
end

def test_should_barf_if_not_given_valid_url
assert_raises GdsApi::Base::InvalidAPIURL do
ConcreteApi.new('invalid-url')
Expand Down

0 comments on commit 7bdc7f0

Please sign in to comment.