JBC Cache Keywords

This section shows the keywords that are used for global caching (cache that is shared across one or more application servers).

There are two keywords CachePut and CacheGet which differs from all other keywords that are added in global caching. These two keywords store data globally and not at the thread level.

The TAFJLocalCacheFactory provider is a local cache provider to an application server node and does not share data across a cluster of application servers. But, an Apache Ignite cache provider shares data across a cluster of application servers. These shared cache keywords are:

Keyword configuration Description

jVar worked = SharedCachePut(jVar cacheName, jVar key, jVar value)

cacheName is a cache, which is defined in either the caching.properties, ignite-caching.xml or other GRID provider properties file. It returns 1, if the key or value was stored in cacheName else 0.

VarCache is the default cache set up for VARs. Unlike CachePut, the cache will not be created for you if it does not exist. It must be configured. If the VAR is a string and the cache provider supports encryption, then the VAR will be encrypted and stored in the cache.

jVar value = SharedCacheGet(jVar cacheName, jVar key)

It retrieves the key from the cache cacheName

jVar worked = SharedCacheClear(jVar cacheName)

It clears the cache cacheName . If the cache is cleared, then 1 is returned else 0.

jVar worked = SharedCacheDelete(jVar cacheName, jVar key)

It removes the key from the cache cacheName. If the key is removed successfully, then 1 is returned else 0.

jVar worked = SharedCacheExists(jVar cacheName, jVar key)

It checks if the key exists in the cache cacheName. If the key is found, then 1 is returned else 0.

jVar keyList = SharedCacheKeyList(jVar cacheName, jVar seperatorChar)

It returns the keyList separated by seperatorChar for the cache cacheName.

TIPS: You can store jVar in a remote Ignite cache without any extra configuration. It is recommended that you use SharedCachePut or SharedCacheGet to replace CachePut or CacheGet while sharing data between threads.

For database records, if the tables are configured in TAFJ_CACHE, then there is no need to use any caching functions. This is because, you can cache the tables by doing a READ on the record. For more information, see Setting up TAFJ Caching.

The following example shows the usage of JBC cache keywords.

PROGRAM TEST.CACHE.SHARED
	CACHE.NAME="VarCache"
	KEYVALUE="KEY1"
	SharedValue = SharedCachePut(CACHE.NAME,KEYVALUE,”Value1”)
	SharedValue = SharedCachePut(CACHE.NAME,”key2”,”Value2”)
	SharedValue = SharedCacheKeyList(CACHE.NAME, "-")
	SharedValue = SharedCacheGet(CACHE.NAME,KEYVALUE)
	SharedValue = SharedCacheDelete(CACHE.NAME,KEYVALUE)
	SharedCacheClear(CACHE.NAME)
     
	CRT "Testing file descriptor"
	fname = "TEST.CACHE.FREE.DELETE"
	EXECUTE "DELETE-FILE TEST.CACHE.FREE.DELETE"
	EXECUTE "CREATE-FILE TEST.CACHE.FREE.DELETE" CAPTURING output
	OPEN fname TO fd ELSE
		CRT "Unable to open the file '":fname:"'"
		ASSERTTRUE(0)
	END

	WRITE "12345678" TO fd, "item"

	SharedValue = SharedCachePut(CACHE.NAME,"key", fd) 
	SharedValue = SharedCacheGet(CACHE.NAME, "key")
  
    
	CRT "Reading SharedValue"

	READ actual FROM SharedValue, "item" ELSE
	CRT "Unable to read from the SharedValue file '":fname:"' after getting from the cache"
        
	END
    
	EXECUTE "SELECT TEST.CACHE.FREE.DELETE" CAPTURING output
	READLIST KEY.LIST ELSE KEY.LIST = ''
	SELECT KEY.LIST
	SharedValue = SharedCachePut(CACHE.NAME, "key", KEY.LIST)
	SharedValue = SharedCacheGet(CACHE.NAME, "key")
    
	NUMRECS = 0
	DONE = 0
	RESULT=""
	LOOP
	READNEXT id FROM SharedValue ELSE DONE = 1
	UNTIL DONE DO
	READ actual FROM fd, id ELSE
	CRT "Unable to read id '":id:"' after getting from the shared cache"
	END
	CRT actual
	NUMRECS = NUMRECS + 1
	REPEAT
	EXECUTE "DELETE-FILE TEST.CACHE.FREE.DELETE" CAPTURING output
  
	CRT "Finished"

END
		

Copyright © 2020- Temenos Headquarters SA

Published on :
Wednesday, October 12, 2022 6:42:20 PM IST

Feedback
x