From: <one...@us...> - 2003-04-04 13:52:04
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/cache In directory sc8-pr-cvs1:/tmp/cvs-serv7478/hibernate/cache Modified Files: ReadOnlyCache.java Timestamper.java Added Files: NonstrictReadWriteCache.java Log Message: added NonstrictReadWriteCache fixed problem with proxy.getId() for an interface proxy --- NEW FILE: NonstrictReadWriteCache.java --- package net.sf.hibernate.cache; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class NonstrictReadWriteCache implements CacheConcurrencyStrategy { private final Cache cache; private static final Log log = LogFactory.getLog(ReadWriteCache.class); public NonstrictReadWriteCache(Cache cache) { this.cache=cache; } public Object get(Object key, long txTimestamp) throws CacheException { Object result = cache.get(key); if ( result!=null && !(result instanceof Long) ) { if ( log.isDebugEnabled() ) log.debug("Cache hit: " + key); return result; } return null; } public void lock(Object key) throws CacheException { //cache.put(key, null); } public boolean put(Object key, Object value, long txTimestamp) throws CacheException { Object result = cache.get(key); if ( result==null ) { if ( log.isDebugEnabled() ) log.debug("Caching new: " + key); } else if ( result instanceof Long && ( (Long) result ).longValue() < txTimestamp / Timestamper.ONE_MS // note that this is not guaranteed to be correct in a cluster // because system times could be inconsistent ) { if ( log.isDebugEnabled() ) log.debug("Caching invalidated: " + key); } else { return false; //note early exit } cache.put(key, value); return true; } public void release(Object key) throws CacheException { if ( log.isDebugEnabled() ) log.debug("Invalidating: " + key); cache.put( key, new Long( Timestamper.next() / Timestamper.ONE_MS ) ); } } Index: ReadOnlyCache.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/cache/ReadOnlyCache.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ReadOnlyCache.java 5 Jan 2003 02:11:20 -0000 1.3 --- ReadOnlyCache.java 4 Apr 2003 13:51:59 -0000 1.4 *************** *** 20,24 **** public synchronized Object get(Object key, long timestamp) throws CacheException { Object result = cache.get(key); ! if ( result!=null ) log.debug("Cache hit: " + key); return result; } --- 20,24 ---- public synchronized Object get(Object key, long timestamp) throws CacheException { Object result = cache.get(key); ! if ( result!=null && log.isDebugEnabled() ) log.debug("Cache hit: " + key); return result; } *************** *** 30,34 **** public synchronized boolean put(Object key, Object value, long timestamp) throws CacheException { ! log.debug("Caching: " + key); cache.put(key, value); return true; --- 30,34 ---- public synchronized boolean put(Object key, Object value, long timestamp) throws CacheException { ! if ( log.isDebugEnabled() ) log.debug("Caching: " + key); cache.put(key, value); return true; Index: Timestamper.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/cache/Timestamper.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Timestamper.java 5 Jan 2003 02:11:20 -0000 1.3 --- Timestamper.java 4 Apr 2003 13:51:59 -0000 1.4 *************** *** 10,22 **** private static short counter = 0; private static long time; public synchronized static long next() { ! long newTime = System.currentTimeMillis() << 16; if (time<newTime) { time = newTime; counter = 0; } ! else if (counter<Short.MAX_VALUE) { counter++; } --- 10,24 ---- private static short counter = 0; private static long time; + private static final int BIN_DIGITS = 12; + public static final short ONE_MS = 1<<BIN_DIGITS; public synchronized static long next() { ! long newTime = System.currentTimeMillis() << BIN_DIGITS; if (time<newTime) { time = newTime; counter = 0; } ! else if (counter < ONE_MS - 1 ) { counter++; } |