gds-api-adapters 52.8.0 → 53.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59d74e1655c62452778dc3ac251578719cef33edf2fbe8ae00e2879807ea762b
4
- data.tar.gz: ff1a65569b144dc72dfa9653a7b2bac38d3b7c27b8825dab52e1a5f364c5f115
3
+ metadata.gz: fe7a50e0626b484068f1cf7cf7f43495cb2a47a264f3b82fb081cf37bb091b19
4
+ data.tar.gz: 0ae38cb74f6563bd85c50f7991c2a6a83cc11d091842d4c326d98f3b07125c94
5
5
  SHA512:
6
- metadata.gz: b514212d519183c9a6bc7f1f18cd9e86249262b69f9336872c015b88302b5dca52de406e5261a9ee3514d0bbbed7bfb321c8ef0b8de882be0959e20d069a2e89
7
- data.tar.gz: c3d785f2cd20a9801f0b58d5ecf0c0e5c68f770845833e73ccc4c07787a16be32ad45ef213a141bd0f7d32b411b651fec962100e32aad74ee7cd500afc607eda
6
+ metadata.gz: 3d2240ddfa6bbbd7cbd7995a7c8f9a53d8545a5822ae8951dc0ec0190620db31cf0f1d78b2743dab9a3c10d4015e4a81f0b4f05f0fb6ce64f18d069839493854
7
+ data.tar.gz: e2be4f4b1788a402ac7f916c2997b9c8f920e7e60c8081da9ba4c2ca9b47f92d760e2511f6f072bbc4d0387a92756347726169c9843aade37a736cf230b9189d
@@ -1,9 +1,7 @@
1
1
  require_relative 'response'
2
2
  require_relative 'exceptions'
3
3
  require_relative 'version'
4
- require_relative 'null_cache'
5
4
  require_relative 'govuk_headers'
6
- require 'lrucache'
7
5
  require 'rest-client'
8
6
  require 'null_logger'
9
7
 
@@ -11,27 +9,7 @@ module GdsApi
11
9
  class JsonClient
12
10
  include GdsApi::ExceptionHandling
13
11
 
14
- # Cache TTL will be overridden for a given request/response by the Expires
15
- # header if it is included in the response.
16
- #
17
- # LRUCache doesn't respect a cache size of 0, and instead effectively
18
- # creates a cache with a size of 1.
19
- def self.cache(size = DEFAULT_CACHE_SIZE, ttl = DEFAULT_CACHE_TTL)
20
- @cache ||= LRUCache.new(max_size: size, ttl: ttl)
21
- end
22
-
23
- # Set the caching implementation. Default is LRUCache. Can be Anything
24
- # which responds to:
25
- #
26
- # [](key)
27
- # []=(key, value)
28
- # store(key, value, expiry_time=nil) - or a Ruby Time object
29
- #
30
- class << self
31
- attr_writer :cache
32
- end
33
-
34
- attr_accessor :logger, :options, :cache
12
+ attr_accessor :logger, :options
35
13
 
36
14
  def initialize(options = {})
37
15
  if options[:disable_timeout] || options[:timeout].to_i < 0
@@ -39,15 +17,6 @@ module GdsApi
39
17
  end
40
18
 
41
19
  @logger = options[:logger] || NullLogger.instance
42
- disable_cache = options[:disable_cache] || ENV.fetch("GDS_API_DISABLE_CACHE", false)
43
-
44
- if disable_cache || options[:cache_size]&.zero?
45
- @cache = NullCache.new
46
- else
47
- cache_size = options[:cache_size] || DEFAULT_CACHE_SIZE
48
- cache_ttl = options[:cache_ttl] || DEFAULT_CACHE_TTL
49
- @cache = JsonClient.cache(cache_size, cache_ttl)
50
- end
51
20
  @options = options
52
21
  end
53
22
 
@@ -70,8 +39,6 @@ module GdsApi
70
39
  end
71
40
 
72
41
  DEFAULT_TIMEOUT_IN_SECONDS = 4
73
- DEFAULT_CACHE_SIZE = 100
74
- DEFAULT_CACHE_TTL = 15 * 60 # 15 minutes
75
42
 
76
43
  def get_raw!(url)
77
44
  do_raw_request(:get, url)
@@ -142,7 +109,7 @@ module GdsApi
142
109
  if params
143
110
  additional_headers.merge!(self.class.json_body_headers)
144
111
  end
145
- response = do_request_with_cache(method, url, (params.to_json if params), additional_headers)
112
+ response = do_request(method, url, (params.to_json if params), additional_headers)
146
113
  rescue RestClient::Exception => e
147
114
  # Attempt to parse the body as JSON if possible
148
115
  error_details = begin
@@ -201,45 +168,6 @@ module GdsApi
201
168
  )
202
169
  end
203
170
 
204
- def do_request_with_cache(method, url, params = nil, additional_headers = {})
205
- # Only read GET requests from the cache: any other request methods should
206
- # always be passed through. Note that this means HEAD requests won't get
207
- # cached, but that would involve separating the cache by method and URL.
208
- # Also, we don't generally make HEAD requests.
209
- use_cache = (method == :get)
210
-
211
- if use_cache
212
- cached_response = @cache[url]
213
- return cached_response if cached_response
214
- end
215
-
216
- response = do_request(method, url, params, additional_headers)
217
-
218
- if use_cache
219
- cache_time = response_cache_time(response)
220
- # If cache_time is nil, this will fall back on @cache's default
221
- @cache.store(url, response, cache_time)
222
- end
223
-
224
- response
225
- end
226
-
227
- # Return either a Time object representing the expiry time of the response
228
- # or nil if no cache information is provided
229
- def response_cache_time(response)
230
- if response.headers[:cache_control]
231
- cache_control = Rack::Cache::CacheControl.new(response.headers[:cache_control])
232
-
233
- if cache_control.private? || cache_control.no_cache? || cache_control.no_store?
234
- Time.now.utc
235
- elsif cache_control.max_age
236
- Time.now.utc + cache_control.max_age
237
- end
238
- elsif response.headers[:expires]
239
- Time.httpdate response.headers[:expires]
240
- end
241
- end
242
-
243
171
  def do_request(method, url, params = nil, additional_headers = {})
244
172
  loggable = { request_uri: url, start_time: Time.now.to_f }
245
173
  start_logging = loggable.merge(action: 'start')
@@ -1,4 +1 @@
1
1
  require 'gds_api/json_client'
2
- require 'gds_api/null_cache'
3
-
4
- GdsApi::JsonClient.cache = GdsApi::NullCache.new
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '52.8.0'.freeze
2
+ VERSION = '53.0.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 52.8.0
4
+ version: 53.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-10 00:00:00.000000000 Z
11
+ date: 2018-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: lrucache
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 0.1.1
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 0.1.1
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: null_logger
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -387,7 +373,6 @@ files:
387
373
  - lib/gds_api/mapit.rb
388
374
  - lib/gds_api/maslow.rb
389
375
  - lib/gds_api/middleware/govuk_header_sniffer.rb
390
- - lib/gds_api/null_cache.rb
391
376
  - lib/gds_api/organisations.rb
392
377
  - lib/gds_api/performance_platform/data_in.rb
393
378
  - lib/gds_api/performance_platform/data_out.rb
@@ -1,11 +0,0 @@
1
- module GdsApi
2
- class NullCache
3
- def [](_k)
4
- nil
5
- end
6
-
7
- def []=(k, v); end
8
-
9
- def store(k, v, expiry_time = nil); end
10
- end
11
- end