at.spardat.enterprise.cache.TransparentCacheDescriptor Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* s IT Solutions AT Spardat GmbH - initial API and implementation
*******************************************************************************/
package at.spardat.enterprise.cache;
/**
* Describes a transparent cache. That is a cache, which is able to load
* objects on its own. Actually this is done by calling the load-method in
* this descriptor, which must be overwritten by an application specific
* subclass.
*
* In order to create a transparent cache, first create a subclass-instance of
* TransparentCacheDescripor and register this object with the
* CacheManager.
*/
public abstract class TransparentCacheDescriptor extends ICacheDescriptor {
/**
* Defines the properties of a transparent cache.
*
* @param name the name of the cache
* @param maxSize maximum number of entries in the cache. If less equal zero,
* the cache has unlimited size.
* @param maxAgeMillis the time in milliseconds denoting how long a entry may
* reside in the cache before beeing evicted. If less equal zero,
* there is no age limitation. If greater than zero, this value
* must not be less than 1000.
* @throws IllegalArgumentException if maxAgeMillis greater than zero and less than 1000.
*/
public TransparentCacheDescriptor (String name, int maxSize, int maxAgeMillis) {
name_ = name;
maxSize_ = maxSize;
maxAgeMillis_ = maxAgeMillis;
if (maxAgeMillis_ > 0) {
if (maxAgeMillis_ < 1000) throw new IllegalArgumentException ("maxAgeMillis less than 1000");
}
}
/**
* @see at.spardat.enterprise.cache.ICacheDescriptor#getName()
*/
public String getName() {
return name_;
}
/**
* @see at.spardat.enterprise.cache.ICacheDescriptor#isTransparent()
*/
public boolean isTransparent() {
return true;
}
/**
* @see at.spardat.enterprise.cache.ICacheDescriptor#load(Object)
*/
public abstract Object load(Object key);
/**
* @see at.spardat.enterprise.cache.ICacheDescriptor#getMaxAgeMillis()
*/
public long getMaxAgeMillis() {
return maxAgeMillis_;
}
/**
* @see at.spardat.enterprise.cache.ICacheDescriptor#getMaxSize()
*/
public int getMaxSize() {
return maxSize_;
}
/**
* @see at.spardat.enterprise.cache.ICacheDescriptor#getMaxAgeSpreadPct()
*/
public int getMaxAgeSpreadPct() {
return maxAgeSpreadPct_;
}
/**
* Sets the spread of cache entry duration.
*
* @see at.spardat.enterprise.cache.ICacheDescriptor#getMaxAgeSpreadPct()
*/
public void setMaxAgeSpreadPct (int pct) {
maxAgeSpreadPct_ = pct;
}
private String name_;
private int maxSize_;
private int maxAgeMillis_;
private int maxAgeSpreadPct_;
}