The Cache API Class - responsible for managing external access to the Fielo Platform Cache - allows you turn on/off some features of the FieloPLT Platform Cache.
Platform cache & testing
The FieloPLT.CacheAPI class is mostly used when running tests.With the introduction of the platform cache in the rules engine and Fielo triggers processing on Spring '21, all Fielo configuration objects are being stored in the cache, enhancing the performance of the rules engine. However, this can cause some trouble if you use the Org data (SeeAllData = true) when writing your test classes.
If that is your case, run the methods explained in this page in order to disable cache before running your tests; otherwise you will receive an error.
enableOnDemand(status)
static void enableOnDemand(Boolean status)
Use this method in order to enable or disable the on demand assembling of the cache.
Assembling the cache during the execution may consume additional SOQL queries. If your development or your test class is hitting Salesforce's SOQL limit, this method will reduce the access to the database (number of SOQL queries).
Parameters
| Parameter | Type | Description |
|---|---|---|
status |
Boolean |
When true, the cache will be assembled on the run time. When false, it disables the on demand assembling of the cache. On demand assembling of the cache is disabled by default. |
Examples
The following example would disable cache on demand assembling for all test methods of the test class, using static block.
@isTest
private class MyTestClass {
// disabling on demand cache assembling
static {
FieloPLT.CacheAPI.enableOnDemand(false);
}
@istest
static void unitTestOne() {
// Create Fielo Configuration
// Create Pre-conditions
// Consume Fielo Configuration (Processing)
}
@istest
static void unitTestTwo() {
// Create Fielo Configuration
// Create Pre-conditions
// Consume Fielo Configuration (Processing)
}
}The following example would disable cache on demand assembling for all test methods of the test class, using testSetup.
@isTest
private class MyTestClass {
@TestSetup
public static void createData() {
FieloPLT.CacheAPI.enableOnDemand(false);
// Create Fielo Configuration
}
@istest
static void unitTestOne() {
// Create Pre-conditions
// Consume Fielo Configuration (Processing)
}
@istest
static void unitTestTwo() {
// Create Pre-conditions
// Consume Fielo Configuration (Processing)
}
}The following example would disable cache on demand assembling for one specific method of the test class.
@isTest
private class MyTestClass {
@istest
static void unitTestOne_withoutOnDemandCache() {
FieloPLT.CacheAPI.enableOnDemand(false);
// Create Pre-conditions
// Consume Fielo Configuration (Processing)
}
@istest
static void unitTestTwo_usingOnDemandCache() {
// Create Pre-conditions
// Consume Fielo Configuration (Processing)
}
}enableCacheAccess(status)
static void enableCacheAccess(Boolean status)
This method enables or disables the cache access(read/write). For example, when writing apex test methods with the notation @isTest (SeeAllData=true), trying to write to the org's cache may result in an exception. To avoid that, you must call the FieloPLT.CacheAPI.enableCacheAccess(false) before creating Fielo configuration objects.
Parameters
Here you'll find how the API can be used and a definition of its parameters.
| Parameter | Type | Description |
|---|---|---|
status |
Boolean |
When false, the cache will not be persisted (saved) in the org's cache. When true, the cache will be saved whenever a Fielo configuration object is created. Cache access is enabled by default. |
Example
The following example would disable cache access for all test methods of the class using static block.
@isTest
private class MyTestClass {
// disabling cache access
static {
FieloPLT.CacheAPI.enableCacheAccess(false);
}
@istest (SeeAllData=true)
static void unitTestOne() {
// Create Fielo Configuration
// Create Pre-conditions
// Consume Fielo Configuration (Processing)
}
@istest (SeeAllData=true)
static void unitTestTwo() {
// Create Fielo Configuration
// Create Pre-conditions
// Consume Fielo Configuration (Processing)
}
}execute(params)
static object execute(String param)
Executes internal cache methods.
Tip: Run before integrations
It'd be a good idea to run this method before you kick off a high-volume integration or an external data sync. This way, you can prevent the cache from updating itself mid-execution.
Parameters
| Parameter | Type | Description |
|---|---|---|
| param | String | Name of the method to be executed. Supported methods: - refresh Note that if the param is not recognized as an internal method, an exception will be raised: The CacheAPI.execute API received an invalid parameter: <paramValue> |
Example
The following example would refresh the entire Fielo Platform Cache (Organization-Wide).
FieloPLT.CacheAPI.execute('refresh');