Skip to content

User Guide: SDKs > VoltMX Iris SDK > Cache Service Response for Integration and Object Service

Cache Service Response for Integration and Object Service

The Cache service response feature provides a non -persistent cache for storing response from integration and object service operations. The stored response can be retrieved by cacheID. Consequently, you can avoid making additional network calls for read-only data.

UsageOptional parameters useCache, cacheID and expiryTime are used to save and retrieve the responses from the cache for both Integration Service and Object Service. Note: Cache size is 100 by default .
ParameterTypeDescription
useCacheBooleanThe parameter to enable the cache service. If the parameter is enabled, SDK generates a unique key for the operation and cache the result with it. The same key is sent in response JSON with key cacheID. Existing entries with the same key will be overridden.
cacheIDStringKey to set or retrieve the mapping from the cache. If the key is not found, the requested operation is performed and the response is mapped to a key in the cache.
expiryTimeNon zero positive IntegerExpiry time in seconds for the key in cache. If expired, responses are removed from the cache. The parameter can be set while adding a new response to cache, and it cannot be updated further.
Features SupportedIntegration Service, Object Service fetch
Platforms SupportedIDE
ScopeThe scope of the feature is limited to the application level.
APIIntegration
 IntegrationClient.invokeOperation(operationName, headers, params, successCallback, failureCallback, options) 
ParameterType
Operation NameString
headersJSON
paramsJSON
successCallbackFunction
failueCallbackFunction
optionsJSON

Object Service

 ObjectClient.fetch(options, successCallback, failureCallback)
ParameterType
optionJSON
successCallbackfunction
failureCallbackfunction

Note: You can remove any key from cache explicitly using new voltmx.sdk.ClientCache().remove(cacheID) .

Sample Code

//Integration Service 
function cache_integration_svc_response() {
    var options = {};
    var responseCacheKey;
    options["useCache"] = true;

    //Optional
    //options["cacheID"] = "cachedEmployeeDetailsResponse";
    //options["expiryTime"] = 30;  - Assign expiry time for the current response if desired

    try {
        var serviceName = "integration_service_name";
        // Get an instance of SDK
        var client = voltmx.sdk.getCurrentInstance();
        var integrationSvc = client.getIntegrationService(serviceName);
        var operationName = "operation_name";
        integrationSvc.invokeOperation(operationName, null, null,
            function(response) {
                // Save the response cache key
                responseCacheKey = response["cacheID"];
                voltmx.print("Success: " + JSON.stringify(response));

            },
            function(error) {
                voltmx.print("Failure: " + JSON.stringify(error));
            },
            options);


        // Try fetching employee details using cacheID
        options = {};
        options["useCache"] = true;
        options["cacheID"] = responseCacheKey;

        integrationSvc.invokeOperation(operationName, null, null,
            function(response) {
                // Save the response cache key
                responseCacheKey = response["cacheID"];
                voltmx.print("Success: " + JSON.stringify(response));

            },
            function(error) {
                voltmx.print("Failure: " + JSON.stringify(error));
            },
            options);

    } catch (exception) {
        alert("Integration Service Connect Failed " + exception.message);
    }
}

//Object Service
function cache_object_svc_fetch() {
    var responseCacheKey;

    var objSvc = voltmx.sdk.getCurrentInstance().getObjectService(serviceName, {
        "access": "online"
    });

    var dataObject = new voltmx.sdk.dto.DataObject("ObjectName");

    var options = {
        "dataObject": dataObject
    };

    options["useCache"] = true;

    //Optional
    //options["cacheID"] = "cachedEmployeeDetailsResponse";
    //options["expiryTime"] = 30;  - Assign expiry time for the current response if desired

    objSvc.fetch(options,
        function(response) {
            responseCacheKey = successRes["cacheID"];
            voltmx.print("Success: " + JSON.stringify(response));

        },
        function(error) {
            voltmx.print("Failure: " + JSON.stringify(error));
        });

    // Try fetching employee details using cacheID
    options = {};
    options["useCache"] = true;
    options["cacheID"] = responseCacheKey;

    objSvc.fetch(options,
        function(response) {
            responseCacheKey = successRes["cacheID"];
            voltmx.print("Success: " + JSON.stringify(response));

        },
        function(error) {
            voltmx.print("Failure: " + JSON.stringify(error));
        });
}