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 .
|
||||||||||||||
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)
|
||||||||||||||
Object ServiceObjectClient.fetch(options, successCallback, failureCallback)
|
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)); }); }