From: <ssk...@vh...> - 2005-09-16 08:35:46
|
Author: sskracic Date: 2005-09-16 10:26:30 +0200 (Fri, 16 Sep 2005) New Revision: 816 Modified: ccm-core/trunk/src/com/arsdigita/caching/CacheTable.java Log: A CacheTable instance can now be local, ie. it's possible to suppress cache syncing on per-table basis. Amended constructors to take additional boolean parameter "isShared". Modified: ccm-core/trunk/src/com/arsdigita/caching/CacheTable.java =================================================================== --- ccm-core/trunk/src/com/arsdigita/caching/CacheTable.java 2005-09-15 14:25:13 UTC (rev 815) +++ ccm-core/trunk/src/com/arsdigita/caching/CacheTable.java 2005-09-16 08:26:30 UTC (rev 816) @@ -64,6 +64,7 @@ private static Map s_caches = new Hashtable(); private String m_cacheID; + private boolean m_shared = true; private DynamicList m_list; /** For debugging only. */ @@ -87,10 +88,21 @@ * @throws NullPointerException if <code>id</code> is <code>null</code> */ public CacheTable(final String id) { - this(id, DEFAULT_CACHE_SIZE, DEFAULT_CACHE_AGE); + this(id, DEFAULT_CACHE_SIZE, DEFAULT_CACHE_AGE, true); } /** + * @param isShared should this cache table be synced with other peers in cluster + */ + public CacheTable(final String id, boolean isShared) { + this(id, DEFAULT_CACHE_SIZE, DEFAULT_CACHE_AGE, isShared); + } + + public CacheTable(final String id, int defSize, int defAge) { + this(id, defSize, defAge, true); + } + + /** * <p>Creates cache storage tagged with the passed in identificator. This * tag must be unique in the sense that no other cache table loaded by this * <code>CacheTable</code>'s {@link java.lang.ClassLoader class loader} may @@ -106,13 +118,15 @@ * @param id Unique identifier for the new storage area * @param size Initial default size * @param age Initial default age + * @param isShared should this cache table be synced with other peers in cluster * @pre id != null * @throws NullPointerException if <code>id</code> is <code>null</code> */ - public CacheTable(final String id, int defSize, int defAge) { + public CacheTable(final String id, int defSize, int defAge, boolean isShared) { if ( id == null ) { throw new NullPointerException("id"); } m_cacheID = id; + m_shared = isShared; final Parameter sizeParam = new IntegerParameter ("waf.util.caching." + id + ".size", @@ -278,7 +292,9 @@ } // If peer webservers don't contain the latest value, // remove this entry from their caches. - CacheServlet.removeOutdatedFromPeers(m_cacheID, key, hashCode); + if (m_shared) { + CacheServlet.removeOutdatedFromPeers(m_cacheID, key, hashCode); + } } public synchronized void removeAll() { @@ -293,7 +309,11 @@ * @param key key of the object we're removing from cache */ public void remove(String key) { - remove(m_cacheID, key); + if (m_shared) { + remove(m_cacheID, key); + } else { + removeLocally(key); + } } /** |