Using Data Caching Service
For better performance, some applications might cache their own data, their metadata information, or even their configuration items. BMC Helix Platform provides a Data Caching Service accessible at com.bmc.arsys.rx.services.cache.CacheService to enable applications to cache data, metadata, and configuration items. After the application is deployed, it can use CacheService to create the cache. After the cache is created, application can add data element to the cache. The application's cache data is cleaned up when the application is uninstalled or reinstalled.
The Data Caching Service increases the application performance by reducing the following:
- Time spent on requesting and receiving the data over the network. This facilitates the server to process more requests in a shorter time period.
- Load on the database server by processing the frequently used requests on the services.
Use the Data Caching Service to perform the following tasks:
- Cache internal or external data of the application by using the com.bmc.arsys.rx.services.cache.Cacheable method
- Create a cache for every tenant when creating local variables and storing transient data in those variables. The application's cached data will never leak from one tenant to another.
- Synchronize the cache across servers in a cluster.
- Load custom data and initialize custom cache by using the com.bmc.arsys.rx.services.cache.CacheInitializer method
A CacheConfiguration type is used to configure the cache, and consists of the following attributes:
- Name of the cache
- Maximum size of the cache
The cache size is configurable between 10 MB and 20 MB.
- Cache initializer
If the initializer is not provided, the frequently used items will be added in the cache.
Data Caching Service sample code
The following code snippet illustrates a sample Data Caching Service code format. Application developers can use this service in custom actions, REST Resource, and so on, to retrieve the application's data.
// Get the cache service
CacheService cacheService = ServiceLocator.getCacheService();
// Create a custom cache initializer
CacheInitializer initializer = new CustomCacheInitializer();
// Create cache configuration
CacheConfiguration cacheConfig = new CacheConfiguration(MY_CACHE, 1,initializer);
// Create cache
cacheService.createCache(cacheConfig);
For more information, see the CacheService information in Platform Service Java API Documentation.
Following are methods of the CacheService provided in the REST API call:
Task | Method to use |
---|---|
To get all cache entries | Set<Cacheable> cacheables = cacheService.getAll(cacheName); |
To get specific cache entries | cacheService.get(id) |
To reset the cache entries | cacheService.resetCache(cacheName); |
To delete all cache entries | cacheService.deleteAll(cacheName); |
To delete specific cache entries | cacheService.delete(cacheName, objectId); |
Comments
Log in or register to comment.