Showing results for 
Search instead for 
Did you mean: 

data caching

Former Member
0 Kudos


I would like to make some appliction which takes data from sap. Loading of data takes a lot of time so i decided to cache that data. I put data in some static class to do this.

Is this solution right or is there any other possibility? Does sb. know how is it implemented in MSS teamView iView?

How can i count usage of memory-i have a collection about 10000 object, each object has 5 Strings(av.length about 40chars), and a Vector which links otherobject in this collection?



Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos


1. A static class will do, although I am not quite sure about garabage collection rules.

I think there is a cache service included in KM, but you can also (and I have) create your own portal cache service which basically uses a HashTable (since it is synchronized, not a HashMap) and stores an object with a key to reference it. I've added some simple cache expiry handling as well (I have no threads running which checks expiry, only on a call to a certain element do I throw a CacheExpiredException).

One thing you need to remeber is that when you compile a project and deploy it, it is no longer compatible with the old cached object and you get a ClassCastException when you access it. To avoid this, define a SerialVersionUID on the class (see for example or clear the cache every time the component is redeployed (if you use a static class in the same par file this should happen automatically I think, do I am not completely sure the JVM will reintialize you static class.)

2. Counting memory used

You can either calculate it based on size of the difference objects (a bit hard) or poll used memory before and after you create the objects. I tend to use the last one eventhough other threads might influence it (since it measures memory used by JVM

So the code will be something like:

public class MeasureMemory {
private static final Runtime s_runtime = Runtime.getRuntime ();

	private static long usedMemory ()
		   return s_runtime.totalMemory () -s_runtime.freeMemory ();

    public static void main(String args[]){
        long memUsedBeforeCall = usedMemory() ; 

	//create the objects
	long memUsedAfterCall = usedMemory() ;	
	System.out.println ("Memory used before call:"+memUsedBeforeCall);
	System.out.println("Memory used after call:"+memUsedAfterCall);
	System.out.println("Increase in memory:"+(memUsedAfterCall-memUsedBeforeCall));


Hopes this helps.



Former Member
0 Kudos


thank u very much for ur answer. Now i know that my solution is not bad from a base.

Answers (0)