IMC Epclient 5.0.3

Package at.spardat.enterprise.cache

This package implements a thread safe cache.

See:
          Description

Interface Summary
ICache A cache is a in memory map of key-value-pairs.
ICache.IKeyFilter Is used to filter keys.
 

Class Summary
DefaultCache A cache implementation, where the entries are kept in a HashMap.
ICacheDescriptor This class provides information describing the caching behaviour of a named cache.
TransparentCacheDescriptor Describes a transparent cache.
 

Package at.spardat.enterprise.cache Description

This package implements a thread safe cache. This cache may be used to cache application global data, if

First, a cache must be set up by describing the caching behaviour. Suppose we'd like to cache information about products. This information doesn't change very often, but is very often accessed by the application. All active sessions are using the same information. Then, there is some class modelling a product:
public class Product extends ... {
    // primary key of the product
	private String               id_;
	// information pertaining to a product
	...
}
Before you can access the cache, you have to decide on the following: Exactly that information is described by a so called CacheDescriptor, see TransparentCacheDescriptor.
... class ProductCacheDescriptor extends TransparentCacheDescriptor {

	// constructor specifies cache replacement strategy
	public ProductCacheDescriptor () {
		super ("products", // name of the cache
		       1000,       // maximum number of entries in the cache
		       ICacheDescriptor.MILLIS_PER_HOUR * 2     // maximum object lifetime in cache is 2 hours
		      );
	}
	
	// the load-method is able to load a particular product for an id
	public Object load (Object key) {
		String          produktId = (String) key;
		Object          toReturn;
		// access the database and load the product for key.
		toReturn = ...
		return toReturn;
	}
	
}
The cache descriptor might be an inner class of a DataAccessObject-class.

If you want an application global cache, the next step is to create the cache with the defined descriptor and put it into a static instance variable as follows:

public class ProductDAO ... {
	private static ICache            productCache_ = new DefaultCache (new ProductCacheDescriptor());

	// This methods is an example for cache usage
	public Product findById (String id) {
		return (Product) productCache_.lookup (id);
	}
	
	// thats the descriptor class we've shown above
	private static class ProductCacheDesciptor extends Transparent ...
		// shown above
	}
}
Finally, the cache may be accessed using the methods of ICache.


IMC Epclient 5.0.3