Class: RedfishClient::CachingConnector

Inherits:
Connector
  • Object
show all
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

Methods inherited from Connector

#add_headers, #delete, #patch, #post, #remove_headers

Constructor Details

#initialize(url, verify = true) ⇒ CachingConnector

Create new caching connector.

Parameters:

  • url (String)

    base url of the Redfish service

  • verify (Boolean) (defaults to: true)

    verify SSL certificate of the service



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.

Parameters:

  • path (String)

    path to the resource, relative to the base url

Returns:

  • (Excon::Response)

    response object



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