![JAR search and dependency download from the Maven repository](/logo.png)
org.hibernate.cache.UpdateTimestampsCache Maven / Gradle / Ivy
The newest version!
//$Id: UpdateTimestampsCache.java 10811 2006-11-15 14:44:34Z [email protected] $
package org.hibernate.cache;
import java.io.Serializable;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.cfg.Settings;
/**
* Tracks the timestamps of the most recent updates to particular tables. It is
* important that the cache timeout of the underlying cache implementation be set
* to a higher value than the timeouts of any of the query caches. In fact, we
* recommend that the the underlying cache not be configured for expiry at all.
* Note, in particular, that an LRU cache expiry policy is never appropriate.
*
* @author Gavin King
* @author Mikheil Kapanadze
*/
public class UpdateTimestampsCache {
public static final String REGION_NAME = UpdateTimestampsCache.class.getName();
private static final Log log = LogFactory.getLog(UpdateTimestampsCache.class);
private Cache updateTimestamps;
private final String regionName;
public void clear() throws CacheException {
updateTimestamps.clear();
}
public UpdateTimestampsCache(Settings settings, Properties props) throws HibernateException {
String prefix = settings.getCacheRegionPrefix();
regionName = prefix == null ? REGION_NAME : prefix + '.' + REGION_NAME;
log.info( "starting update timestamps cache at region: " + regionName );
this.updateTimestamps = settings.getCacheProvider().buildCache( regionName, props );
}
public synchronized void preinvalidate(Serializable[] spaces) throws CacheException {
//TODO: to handle concurrent writes correctly, this should return a Lock to the client
Long ts = new Long( updateTimestamps.nextTimestamp() + updateTimestamps.getTimeout() );
for ( int i=0; i= timestamp.longValue() ) {
return false;
}
}
}
return true;
}
public void destroy() {
try {
updateTimestamps.destroy();
}
catch (Exception e) {
log.warn("could not destroy UpdateTimestamps cache", e);
}
}
public Cache getCache() {
return updateTimestamps;
}
public String getRegionName() {
return regionName;
}
public String toString() {
return "UpdateTimestampeCache";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy