Using Data Caching Service
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 you create local variables and store transient data in those variables. The application's cached data is never shared among tenants.
- Synchronize the cache across servers in a cluster.
- Load custom data and initialize a 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 cacheThe cache size is configurable between 10 MB and 20 MB.
- Cache initializerIf the initializer is not provided, the frequently used items will be added to the cache.
Data Caching Service sample code
The following sample shows the Data Caching Service code:
To retrieve the application's data, application developers can use the Data Caching Service in custom actions, REST resources, and so on.
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 details, see the CacheService information in Platform Service Java API Documentation.
The following CacheService methods are provided in the REST API call:
Task | Method to use |
---|---|
Get all cache entries | Set<Cacheable> cacheables = cacheService.getAll(cacheName); |
Get specific cache entries | cacheService.get(id) |
Reset the cache entries | cacheService.resetCache(cacheName); |
Delete all cache entries | cacheService.deleteAll(cacheName); |
Delete specific cache entries | cacheService.delete(cacheName, objectId); |
Troubleshooting
This section describes how to resolve issues that you might encounter when using the Data Caching Service.
If you receive the following error when you use the Data Caching Service code:
com.bmc.arsys.server.rx.services.RxFrameworkException: [ERROR (12049): Please provide correct bundle scope. Actual Bundle deployed is not the bundle scope passed :; default-bundle-scope is null / empty]
To resolve the issue, perform the following tasks:
- Get the following jar from the location where you have installed Action Request System and add this jar in your project classpath.
<ARInstalledFolder/Pod>/ARSystem/lib/upgradeutils/com.bmc.arsys.common-<version>.jar
Add the following dependencies to your bundle pom.xml file:
<dependency>
<groupId>com.bmc.arsys</groupId>
<artifactId>com.bmc.arsys.common</artifactId>
<version>${rx-sdk.version}</version>
<scope>provided</scope>
</dependency>Add the following code before the Data Caching Service code:
ThreadLocalContext.putValue(RxBundle.DEFAULT_BUNDLE_SCOPE_KEY, "<applicationID>");For example:
ThreadLocalContext.putValue(RxBundle.DEFAULT_BUNDLE_SCOPE_KEY, "<applicationID>");
// 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);