I want to use the Cache Service API in EP6SP2 and encountered at runtime a class cast exception when casting the retrieved cache service to ICacheService, see next statement:
ICacheService cachesvc = (ICacheService)PortalRuntime.getRuntimeResources().getService(ICacheService.KEY);
I have included the com.sap.portal.compatibility50.cacheapi.jar file in the lib folder of PORTAL-INF. Also I did an import of the class com.sapportals.portal.prt.service.cache.ICacheService
Why do I get this exception and what can I do to solve this problem? And is using the Cache Service API still a recommended way of working in EP6 (it seems it originates from EP5)?
Hi,
I'm not sure about your error. But for me the caching worked when I added "com.sap.portal.compatibility50.cache"
to the "SharingReference" property in the portalapp.xml of the application. And if you do this you don't have to add this jar to your lib-folder.
Actually I think you should remove the jar from the lib-folder and try it by setting the "SharingReference".
Best regards
Mirko
Hi Leendert,
you don't have to put the JAR into your PAR. The reason is simple: At runtime,
PortalRuntime.getRuntimeResources().getService(ICacheService.KEY);
returns an instance of the class loaded from the JAR which is part of the portal (irj) application, whereas you try to cast it to the class type loaded from the JAR you have added within your PAR -> ClassCastException.
For compile time, just set the JAR into your build path, but do not add runtime resources of the portal into your JAR. Never.
Some additional remarks:
- You can use [ code ] / [/ code] (without spaces) here on SDN to mark code, see above.
- It is a good convention to have a space between a cast operator and the object to be casted, see http://java.sun.com/docs/codeconv/html/CodeConventions.doc7.html#682
- Please use the yellow star button on helping replies to award points for the helpers; you haven't done in the past.
Hope it helps
Detlev
Add a comment