cancel
Showing results for 
Search instead for 
Did you mean: 

Creating new cache instance

Former Member
0 Kudos

I want to create a new KM cache which is not preconfigured.

According to https://media.sdn.sap.com/javadocs/NW04/SP12/km/com/sapportals/wcm/util/cache/CacheFactory.html

this should be possible with the getCache(String cacheID, Properties properties) method.

I tried the following code:

String cacheID = CacheFactory.getUniqueCacheID();

Properties cacheProp = new Properties(); cacheProp.setProperty(CacheFactory.CFG_MAX_CACHE_SIZE_KEY, "1000000"); cacheProp.setProperty(CacheFactory.CFG_CAPACITY_KEY, "500"); cacheProp.setProperty(CacheFactory.CFG_MAX_ENTRY_SIZE_KEY, "500");

cacheProp.setProperty(CacheFactory.CFG_AVERAGE_ENTRY_SIZE_KEY, "20000"); cacheProp.setProperty(CacheFactory.CFG_SINGLETON_KEY, "true");

cacheProp.setProperty(CacheFactory.CFG_DEFAULT_TIME_TO_LIVE_KEY, "0"); cacheProp.setProperty(CacheFactory.CFG_STORAGE_CLASS_KEY,CacheFactory.CFG_MEMORY_KEY);

try {

CacheFactory cacheFac = CacheFactory.getInstance();

cache = cacheFac.getCache(cacheID, cacheProp);

} catch (Exception e) {

e.printStackTrace();

}

Unfortunately I always get an exception. Is where any other property what I have to set?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi!

Mandatory cache properties are:

CacheFactory.CFG_CACHE_CLASS_KEY, e.g. ICache.DEFAULT_CACHE_CLASS (for memory caches)

CacheFactory.CFG_CACHE_TYPE_KEY, e.g. CacheFactory.CFG_MEMORY_KEY (for memory caches)

CacheFactory.CFG_SINGLETON_KEY, e.g. ICache.DEFAULT_SINGLETON (true)

CacheFactory.CFG_STORAGE_CLASS_KEY is needed only for persistent caches and will contain

a Java class that stores the content in the filesystem.

bye, Dirk

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Please reproduce the exception /stack trace , so that we can help you out with your problem.

Regards,

Harish

Former Member
0 Kudos

unfortunately the stack trace isn't very helpful:

com.sapportals.wcm.util.cache.CacheException at com.sapportals.wcm.util.cache.CacheFactory.getCache(CacheFactory.java:257) at

com.test.TransformerHandler.(TransformerHandler.java:71) at

com.test.XSLTransformer.doContent(XSLTransformer.java:26) at com.sapportals.portal.prt.component.AbstractPortalComponent.serviceDeprecated(AbstractPortalComponent.java:209) at com.sapportals.portal.prt.component.AbstractPortalComponent.service(AbstractPortalComponent.java:114) at com.sapportals.portal.prt.core.PortalRequestManager.callPortalComponent(PortalRequestManager.java:328) at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:136) at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:189) at com.sapportals.portal.prt.component.PortalComponentResponse.include(PortalComponentResponse.java:215) at com.sapportals.portal.prt.pom.PortalNode.service(PortalNode.java:646) at com.sapportals.portal.prt.core.PortalRequestManager.callPortalComponent(PortalRequestManager.java:328) at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:136) at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:189) at com.sapportals.portal.prt.core.PortalRequestManager.runRequestCycle(PortalRequestManager.java:753) at com.sapportals.portal.prt.connection.ServletConnection.handleRequest(ServletConnection.java:240) at com.sapportals.portal.prt.dispatcher.Dispatcher$doService.run(Dispatcher.java:522) at java.security.AccessController.doPrivileged(Native Method) at com.sapportals.portal.prt.dispatcher.Dispatcher.service(Dispatcher.java:405) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.sap.engine.services.servlets_jsp.server.servlet.InvokerServlet.service(InvokerServlet.java:156) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:390) at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:264) at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:347) at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:325) at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:887) at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:241) at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92) at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:148) at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33) at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41) at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37) at java.security.AccessController.doPrivileged(Native Method) at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:95) at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:160)

The code for instantiating the cache is in the TransformerHandler class.

detlev_beutner
Active Contributor
0 Kudos

Hi Achim,

the problem with the stack trace - as you've already stated - is that's it's not very helpful... If you check line 257 and above of the implementation, you will find a try/catch block of around 18 lines, where in the catch statement a new exception is thrown without providing the stack trace so far. Something which should never be done if the cause for the exception is non-ambiguous and can be passed into the new exception's text.

In such a case, I would advise to do one of the following two things:

- If you want a fast answer, modify the implementation to debug it or at least to get the real root cause; this way you maybe are able to repair the code or to pass valuable information directly to SAP's dev department.

- Open an OSS message with just the problem.

Hope it helps

Detlev

PS: Please consider to reward points for helpful answers on SDN. Thanks in advance!