Business Console 10.7 | webMethods Business Console Documentation | Developing Gadgets for Business Console | Getting Started | Using RESTful Services with Gadgets | Configuring Gadgets to Cache Data Offline
 
Configuring Gadgets to Cache Data Offline
The offline caching capability allows you to configure gadgets to store data offline.
1. Create a gadget. For information about creating a gadget, see Creating HelloWorld Gadget .
2. Enable or disable the offline caching capability for gadgets as follows:
a. Navigate to gadgetDefinition.xml of a respective gadget.
b. Select the Gadget Definition Editor tab and expand Parameters.
c. Click Add.
d. Enter the following parameter in the Name and Value fields respectively:
Name
Value
Offline
True
3. Configure offline stores in the IndexedDB of gadgets by configuring the REST GET call URL as follows:
Note:
You can configure multiple offline stores for a gadget.
a. Navigate to the gadget controller.
b. Define the REST service URL with the caching configuration as follows:
Ensure that the URL is accessible from $scope.url.
{
TASK_INBOX_GET:{url:'/rest/pub/opentasksearch', method:'GET'
isArray:true, serverType:SERVER_TYPES.TE,
headers : {"Content-Type": "application/json"
,"Accept":"application/json"},
caching : {name:'OfflineTaskInbox',
key : {value:'TaskInbox'},
strategy : 'CacheOnly'
}
}
}
where:
*Name is the unique OfflineStore name of a gadget.
*Key is the key value for which the data is stored. Key accepts the following variants as values:
*key:{value:'TaskInbox'} is the constant value configured as a key.
*key:{requestKeyParamName:'cacheKey'} key is extracted from the request parameter.
*key:{requestKeyPath:'payload.key'} key is extracted from the request payload using the JSON path configured.
*key:{responseKeyPath:'response.id'} key is extracted from each item in the response array. The configuration for caching is:
caching : {name:'OfflineTaskInbox',
key:{responseKeyPath:'response.id'},
isArray:true
}
*Strategy is the configuration that controls the lifecycle of the cached content. Strategy accepts the following variants as values:
Note:
If no value is specified for Strategy, then NetworkFirst is specified as the default value.
*strategy:'CacheOnly', where the data is fetched only from the cache. If the data is not found in the cache, then fetch the data from the server and store it in the cache for the first time.
*strategy:'CacheFirst', where the data is first fetched from the cache and then receives new data from the server and updates the cache.
*strategy:'NetworkFirst', where the data is always fetched from the server. If the user is offline then the data is fetched from the cache.