Class: Draisine::CachingClient
- Inherits:
-
Object
- Object
- Draisine::CachingClient
- Defined in:
- lib/draisine/util/caching_client.rb
Defined Under Namespace
Classes: Cache
Instance Attribute Summary collapse
-
#cache_map ⇒ Object
readonly
Returns the value of attribute cache_map.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #fetch_multiple(salesforce_object_name, ids) ⇒ Object (also: #prefetch)
- #find(salesforce_object_name, id) ⇒ Object
-
#initialize(client = Draisine.salesforce_client) ⇒ CachingClient
constructor
A new instance of CachingClient.
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize(client = Draisine.salesforce_client) ⇒ CachingClient
Returns a new instance of CachingClient.
47 48 49 50 |
# File 'lib/draisine/util/caching_client.rb', line 47 def initialize(client = Draisine.salesforce_client) @cache_map = Hash.new {|h,k| h[k] = Cache.new } @client = client end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/draisine/util/caching_client.rb', line 65 def method_missing(method, *args, &block) if client.respond_to?(method) client.__send__(method, *args, &block) else super end end |
Instance Attribute Details
#cache_map ⇒ Object (readonly)
Returns the value of attribute cache_map.
45 46 47 |
# File 'lib/draisine/util/caching_client.rb', line 45 def cache_map @cache_map end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
45 46 47 |
# File 'lib/draisine/util/caching_client.rb', line 45 def client @client end |
Instance Method Details
#fetch_multiple(salesforce_object_name, ids) ⇒ Object Also known as: prefetch
58 59 60 61 62 |
# File 'lib/draisine/util/caching_client.rb', line 58 def fetch_multiple(salesforce_object_name, ids) cache_map[salesforce_object_name].fetch_multiple(ids) do client.fetch_multiple(salesforce_object_name, ids) end end |
#find(salesforce_object_name, id) ⇒ Object
52 53 54 55 56 |
# File 'lib/draisine/util/caching_client.rb', line 52 def find(salesforce_object_name, id) cache_map[salesforce_object_name].fetch(id) do client.find(salesforce_object_name, id) end end |