The Cache property of SalesforceConnection is used for managing cache for Salesforce.com or Database.com objects of this connection. This property is of SalesforceCache type. This class provides a set of methods for creating, enabling, disabling, altering, and deleting cache for Salesforce.com or Database.com objects, and getting cache state.
To create a cache for an object, use one of the overloads of Create method of the SalesforceCache class. One of the overloads accepts a SalesforceCacheItem instance as a parameter. This class represents cache settings for a single Salesforce.com or Database.com object. Create an instance of such class and set the following fields of it:
- TableName - the name of an object (table) to create cache for.
- RefreshInterval - if this time interval passed after last cache refreshing, it will be refreshed again when executing the next query, referencing the cached object.
- RefreshIntervalUnit - the unit that refresh interval is measured in. Can be RefreshIntervalUnit.Hour, RefreshIntervalUnit.Minute, or RefreshIntervalUnit.Second.
- Filter - SOQL WHERE clause to filter cached objects. This parameter is optional. By default, all objects are cached. Note that if you cache only part of objects, the objects that are not cached will never be returned by any query until you delete or modify the cache. Even queries without the filter conditions will return only filtered objects from this table.
- FullRefresh - determines the refresh mode to use. True, if full refresh mode should be used (all objects, matching the filter if such is set, from tho specified table will be queried when performing cache refreshing); false, if smart refresh mode should be used (only objects that were created or modified since the last cache refreshing, will be queried when performing cache refreshing).
Or you may use another overload that accepts these settings as the corresponding parameters.
After creating, you may change the cache parameters using the one of the Alter method overloads. You can change cache settings separately with some overloads or alter all of them wit one call using either an overload, accepting SalesforceCacheItem instance or all settings as separate parameters.
Cache can be enabled or disabled with the Enable and Disable methods of the SalesforceCache, accepting either an object name or a SalesforceCacheItem instance as their parameter. When the cache is disabled, its data is preserved, however all queries to the cached object retrieve its data from Salesforce.com or Database.com and don't use the cache.
Cache is refreshed automatically each refresh interval, however, you can refresh it manually with the Refresh method of SalesforceCache. If refresh interval is set to 0 or negative number, this means that cache is never gets out-of-date and is not refreshed automatically, and the Refresh method is the only way to refresh it.
Cache settings for an object can be retrieved with GetCacheItem method of SalesforceCache. You may get the names of the objects, for which cache exists, using GetCachedTables method of SalesforceCache.
dotConnect for Salesforce cache is a write-through one. When you modify data, this modifications are immediately applied to the remote data and then they are applied to the cache. If dotConnect for Salesforce cannot update the cache because some of the modified data may have been generated by Salesforce.com or Database.com, for example, if there are calculated fields, or some field are not present in the INSERT statement and should take their default values, it queries the modified data from it, and then updates the cache.
To drop the cache use the the Drop method of SalesforceCache, which accepts the name of the table to drop the cache for or a SalesforceCacheItem instance as a parameter. After the cache is dropped, queries to this table will request its data from Salesforce.com or Database.com.