at.spardat.enterprise.cache.ICacheDescriptor 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;
import java.lang.Object;
/**
* This class provides information describing the caching behaviour of a named cache.
*
* @author s2266
*/
public abstract class ICacheDescriptor {
/**
* Returns the name of the described cache.
*/
public abstract String getName();
/**
* Returns true if the described cache is a transparent cache, which
* can load objects by the load method of this descriptor
*/
public abstract boolean isTransparent ();
/**
* This is the load method of a transparent cache. If the cache user
* calls lookup and the key isn't in the cache, this
* method is called to get the cacheable object for the key.
*
* This method may be called in parallel from many threads. You must
* not access instance variables in this method.
*
* @param key the key for which a value should be loaded.
* @return the loaded object. Must not be null. If there are exceptions
* in the course of the load procedure, you must throw a
* RuntimeException.
*/
public abstract Object load (Object key);
/**
* Returns the maximum time in milliseconds a cache entry should be
* accessible in the chache. If this value is less than or equal
* to zero, there is no age limitation.
*/
public abstract long getMaxAgeMillis();
/**
* If the value provided by this method is not zero, the time
* a cache entry resides in the cache before it is beeing evicted is
* spread to a percentage around getMaxAgeMillis(). Suppose,
* getMaxAgeMillis() provides 3600000 (one hour). Then a
* getMaxAgeSpreadPct-value of 10 percent denotes that
* the actual validity-duration of an entry is randomly choosen
* in the range [3600000-360000 ... 360000+360000]. Or more readable,
* the duration is equally distributed between 54 and 66 minutes.
*
* The default implementation of this method is no spread at all.
*
* @return Spread in percents.
*/
public int getMaxAgeSpreadPct() {
return 0;
}
/**
* Returns the maximum number of cached entries in the described cache.
* If this value is less than or equal to zero, the described cache
* does not have a size limitation.
*/
public abstract int getMaxSize();
// number of milliseconds per second
public static final int MILLIS_PER_SECOND = 1000;
// number of millisconds in a minute
public static final int MILLIS_PER_MINUTE = 60000;
// number of milliseconds in a hour
public static final int MILLIS_PER_HOUR = 3600000;
}