Class: Restforce::DB::RecordCache

Inherits:
Object
  • Object
show all
Defined in:
lib/restforce/db/record_cache.rb

Overview

Restforce::DB::RecordCache serves as a means of caching the collections of recently-updated database and Salesforce instances for passed mappings. The general goal is to avoid making repetitive Salesforce API calls or database queries, and ensure a consistent list of objects during a synchronization run.

Instance Method Summary collapse

Constructor Details

#initializeRecordCache

Public: Initialize a new Restforce::DB::RecordCache.



13
14
15
# File 'lib/restforce/db/record_cache.rb', line 13

def initialize
  reset
end

Instance Method Details

#collection(mapping, record_type, options = {}) ⇒ Object

Public: Iterate through the recently-updated instances of the specified type for the passed mapping. Memoizes the records if the collection has not previously been cached.

mapping - A Restforce::DB::Mapping. record_type - A Symbol naming a mapping record type. Valid values are

:salesforce_record_type or :database_record_type.

options - A Hash of options to pass to ‘all` (optional).

Returns an Array of Restforce::DB::Instances::Base.



27
28
29
30
# File 'lib/restforce/db/record_cache.rb', line 27

def collection(mapping, record_type, options = {})
  return cached_value(mapping, record_type) if cached?(mapping, record_type)
  cache(mapping, record_type, mapping.send(record_type).all(options))
end

#resetObject

Public: Reset the cache. Should be invoked between runs to ensure that new options are respected.

Returns nothing.



36
37
38
# File 'lib/restforce/db/record_cache.rb', line 36

def reset
  @cache = Hash.new { |h, k| h[k] = {} }
end