How to define custom cache in MobileFabric Or How to make cached data is available to all users?

This thread was migrated from an old forum. It may contain information that are no longer valid. For further assistance, please post a new question or open a support ticket from the Customer Support portal.

The Kony middleware includes a caching mechanism to cache the result objects returned from service calls. This improves the turn-around time a great deal for static services and/or very common service calls. Examples of service calls where this can be implemented in real time are airport lists for airlines applications, list of feeds that need to be refreshed at a regular interval, and a list of products that need to be updated for a retail application.

Caching is applied to all users across all sessions in a specific node in a Kony Server cluster. Unlike session information, cached items are not shared among different nodes in a cluster. Inputs to the service call are not considered for cache "matching" purposes, so the only logical place to apply this would be for global data that applies to all users.

There is a difference between session and cache. Session data is available for a particular user whereas cached data is available to all users.

The result objects are cached using the service-id and appID as a key. Do not use the same key unless you specifically want to over-write the value cached by middleware.

The cache is not a replacement for storing values in a session.

Cache should be used only for enhanced performance and temporary storage while the business logic should not depend on values stored in cache.

Below are the steps to be implemented for making the cache functionality work in any server using the Kony Middleware.

  • Open "oscache.properties" file and make sure "cache.path " property has the full path to "oscache" directory (Path for OSCache should be /home/core/middleware/middleware-bootconfig/oscache)
  • Oscache.properties:
    • cache.memory=true
    • cache.capacity=10(This is in MB)
    • cache.blocking=false
    • cache.unlimited.disk=true
    • cache.path=/home/core/install/middleware/middleware-bootconfig/oscache

The following API’s are used in order to implement this:

  • insertIntoCache - The method to insert the Result object into cache. The invocation happens for the first time when the service is invoked or if the invocation happens after the cache duration.
  • retrieveFromCache - This method returns the Result object associated with the given key. Returns null if no such mapping exists.

To configure the cache, follow the steps detailed below:

  • Ensure that the service definition file incorporates a parameter called "cacheable" as a <config-param> tag. This can contain either the values "true" or "false". This property ensures that the service call result objects shall be cached after they are processed by the post processor.
    • Eg. <config-param value="true" name="cacheable">
  • While installing the middleware, ensure that the ehcache.xml file is present in the /middleware/middleware-bootconfig/ folder. This file contains the configurations for the cache such as the disk location, time duration etc.
  • You can also cache specific objects in the pre-processor/post-processor and retrieve them in the next call. To cache your own result objects, use the following code:

ResultCache rcache = ResultCacheImpl.getInstance() ;

rcache.insertIntoCache(Object key,Object value) ;

  • To retrieve from cache :

ResultCache rcache = ResultCacheImpl.getInstance() ;

Result resultObject = (Result) rcache.retrieveFromCache(Object key) ;

Hi

Is this applicable to Kony cloud as well?

Thanks

Thank you @Mallikarjuna anegondi​ for sharing this helpful information!