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.

 

Usage

Optional 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 .

Parameter Type Description
useCache Boolean The 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.
cacheID String Key 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.
expiryTime Non zero positive Integer Expiry 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 Supported Integration Service, Object Service fetch
Platforms Supported IDE
Scope The scope of the feature is limited to the application level.
API

Integration

 IntegrationClient.invokeOperation(operationName, headers, params, successCallback, failureCallback, options) 

 

Parameter Type
Operation Name String
headers JSON
params JSON
successCallback Function
failueCallback Function

 

Object Service
 ObjectClient.fetch(options, successCallback, failureCallback)
Parameter Type
option JSON
successCallback function
failureCallback function

NOTE: You can remove any key from cache explicitly using new kony.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 = kony.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"];
                kony.print("Success: " + JSON.stringify(response));

            },
            function(error) {
                kony.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"];
                kony.print("Success: " + JSON.stringify(response));

            },
            function(error) {
                kony.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 = kony.sdk.getCurrentInstance().getObjectService(serviceName, {
        "access": "online"
    });

    var dataObject = new kony.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"];
            kony.print("Success: " + JSON.stringify(response));

        },
        function(error) {
            kony.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"];
            kony.print("Success: " + JSON.stringify(response));

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