Skip to Content
author's profile photo Former Member
Former Member

Caching Service API in EP6

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)?

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 05, 2005 at 11:51 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 05, 2005 at 11:43 AM

    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
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.