GMCacheConfiguration.xml
<?xml version="1.0" encoding="UTF-8"?> <gm-configuration> <cache-configuration> <cache name="GM_SESSION_CACHE" timeToLive="3600000"> <manager class="com.graymound.cache.GMCacheManagerLocal"/> <loaders/> </cache> <cache name="GM_SERVICE_CACHE"> <manager class="com.graymound.cache.GMCacheManagerLocal"/> <loaders> <loader class="com.graymound.service.loader.GMCacheLoaderServiceXML"/> <loader class="com.graymound.module.administration.cache.loader.GMCacheLoaderServiceDB"/> </loaders> </cache> <cache name="GM_MESSAGE_CACHE"> <manager class="com.graymound.cache.GMCacheManagerLocal"/> <loaders> <loader class="com.graymound.module.administration.cache.loader.GMCacheLoaderMessageDB"/> </loaders> </cache> <cache name="GM_REFERENCEDATA_CACHE"> <manager class="com.graymound.cache.GMCacheManagerLocal"/> <loaders> <loader class="com.graymound.module.administration.cache.loader.GMCacheLoaderReferenceDataDB"/> </loaders> </cache> </cache-configuration> </gm-configuration>
GM_SESSION_CACHE
Keeps session information during user-login time.
GM_SERVICE_CACHE
Fill with service class information when application server started.
GM_MESSAGE_CACHE
Fill with message id and message language data when application server started.
HOW TO Writing a simple cache mechanism
- Create a class and implement GMCacheLoader.
- Add unimplemented methods. (load(), lookup(String arg0)).
- When application server started load() function invokes. Fill your cache on load() function.
- If key cannot find on load() function, cache manager invokes lookup(String arg0) function.
- Put your cache to GMCacheConfiguration.xml. You will call this cache from a GraymoundService with name attribute. (TEST_CACHE)
<cache name="TEST_CACHE"> <manager class="com.graymound.cache.GMCacheManagerLocal"/> <loaders> <loader class="com.obss.tutorial.TestCache"/> </loaders> </cache>
Here is simple cache code;
public class TestCache implements GMCacheLoader{ public Map<String, Object> load() { Map<String, Object> map = new HashMap<String, Object>(); map.put("TestData", "212"); return map; } public Object lookup(String arg0) { HashMap<String, String> lMap = new HashMap<String, String>(); lMap.put("TestInfo", "2155"); return lMap; } }
HOW TO Get a value from cache
GMCache cache = GMCacheFactory.getInstance().getCache("TEST_CACHE"); String value = (String) cache.get("TestData ");
HOW TO Put a value to cache
GMCache cache = GMCacheFactory.getInstance().getCache("TEST_CACHE"); cache.put("TestData","322");
