Class: RedfishClient::CachingConnector
- Defined in:
- lib/redfish_client/caching_connector.rb
Overview
Variant of Connector that caches GET responses.
Constant Summary
Constants inherited from Connector
RedfishClient::Connector::DEFAULT_HEADERS
Instance Method Summary collapse
-
#get(path) ⇒ Excon::Response
Issue GET request to service.
-
#initialize(url, verify = true) ⇒ CachingConnector
constructor
Create new caching connector.
-
#reset(path: nil) ⇒ Object
Clear the cached responses.
Methods inherited from Connector
#add_headers, #delete, #patch, #post, #remove_headers
Constructor Details
#initialize(url, verify = true) ⇒ CachingConnector
Create new caching connector.
12 13 14 15 |
# File 'lib/redfish_client/caching_connector.rb', line 12 def initialize(url, verify = true) super @cache = {} end |
Instance Method Details
#get(path) ⇒ Excon::Response
Issue GET request to service.
Request is only issued if there is no cache entry for the existing path.
23 24 25 |
# File 'lib/redfish_client/caching_connector.rb', line 23 def get(path) @cache[path] ||= super end |
#reset(path: nil) ⇒ Object
Clear the cached responses.
Next GET request will repopulate the cache.
30 31 32 33 34 35 36 |
# File 'lib/redfish_client/caching_connector.rb', line 30 def reset(path: nil) if path.nil? @cache = {} else @cache.delete(path) end end |