You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by ma...@apache.org on 2004/08/10 00:56:13 UTC

cvs commit: jakarta-slide/src/share/org/apache/slide/util TxLRUObjectCache.java

masonjm     2004/08/09 15:56:13

  Modified:    src/share/org/apache/slide/store ExtendedStore.java
               src/share/org/apache/slide/util TxLRUObjectCache.java
  Log:
  Added the ability to remove multiple objects from a cache using a key prefix plus a delimiter.
  
  Revision  Changes    Path
  1.18      +24 -10    jakarta-slide/src/share/org/apache/slide/store/ExtendedStore.java
  
  Index: ExtendedStore.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/store/ExtendedStore.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- ExtendedStore.java	28 Jul 2004 09:34:42 -0000	1.17
  +++ ExtendedStore.java	9 Aug 2004 22:56:12 -0000	1.18
  @@ -401,23 +401,23 @@
       		LOG_CHANNEL,
   			Logger.DEBUG );
       	if ( contentStore.cacheResults() && contentCachingEnabled ) {
  -    		contentCache.remove( key );
  +    		contentCache.remove( key.toString(), "_" );
       	}
       	if ( nodeStore.cacheResults() ) {
  -    		objectsCache.remove( key );
  +    		objectsCache.remove( key.toString() );
       	}
       	if ( securityStore.cacheResults() ) {
  -    		permissionsCache.remove( key );
  +    		permissionsCache.remove( key.toString() );
       	}
       	// Locks shouldn't be cached, but just in case.
       	if ( lockStore.cacheResults() ) {
  -    		locksCache.remove( key );
  +    		locksCache.remove( key.toString() );
       	}
       	if ( revisionDescriptorsStore.cacheResults() ) {
  -    		descriptorsCache.remove( key );
  +    		descriptorsCache.remove( key.toString() );
       	}
       	if ( revisionDescriptorStore.cacheResults() ) {
  -    		descriptorCache.remove( key );
  +    		descriptorCache.remove( key.toString(), "-" );
       	}
       }
       
  @@ -1198,6 +1198,20 @@
                   Xid txId = (Xid) activeTransactionBranch.get();
                   txCache.remove(txId, key);
                   getLogger().log("Removing content at '" + key + "' from cache", LOG_CHANNEL, Logger.DEBUG);
  +            } catch (Error e) {
  +                fatalError(e);
  +            } catch (RuntimeException re) {
  +                fatalError(re);
  +            }
  +        }
  +
  +        public void remove(Object key, String delimiter) {
  +            if (globalCacheOff)
  +                return;
  +            try {
  +                Xid txId = (Xid) activeTransactionBranch.get();
  +                txCache.remove(txId, key, delimiter);
  +                getLogger().log("Removing content at '" + key + "' with delimeter '" + delimiter + "' from cache", LOG_CHANNEL, Logger.DEBUG);
               } catch (Error e) {
                   fatalError(e);
               } catch (RuntimeException re) {
  
  
  
  1.6       +64 -4     jakarta-slide/src/share/org/apache/slide/util/TxLRUObjectCache.java
  
  Index: TxLRUObjectCache.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/util/TxLRUObjectCache.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TxLRUObjectCache.java	28 Jul 2004 09:34:28 -0000	1.5
  +++ TxLRUObjectCache.java	9 Aug 2004 22:56:13 -0000	1.6
  @@ -182,6 +182,48 @@
               }
           }
       }
  +    
  +    /**
  +     * <p>
  +     * Removes the object identified by <code>key</code> as well as any objects
  +     * identified by <code>key.toString() + delimiter</code>.
  +     * </p>
  +     * <p>
  +     * Example: <code>remove(xId, "/slide/files", "-")</code> would remove
  +     * <code>/slide/files</code> and <code>/slide/files-1.3</code> but not
  +     * <code>/slide/files/temp</code>.
  +     * 
  +     * @param txId the id of the current transaction or <code>null</code> if not
  +     *             in a transaction.
  +     * @param key the key to remove from the cache.
  +     * @param delimiter the delimiter to use to identify subnodes that should be
  +     *                  removed as well.
  +     */
  +    public synchronized void remove(Object txId, Object key, String delimiter) {
  +        if (txId != null) {
  +            // undo any changes
  +            Map changeCache = (Map) txChangeCaches.get(txId);
  +            changeCache.remove(key);
  +            prune(changeCache, key, delimiter);
  +
  +            Set deleteCache = (Set) txDeleteCaches.get(txId);
  +            deleteCache.add(key);
  +            deprune(deleteCache, key, delimiter);
  +
  +            // guard logging as preparation is expensive
  +            if (loggingEnabled) {
  +                logger.log(txId + " removed '" + key + "'", logChannel, Logger.DEBUG);
  +            }
  +        } else {
  +            if (globalCache != null) {
  +                globalCache.remove(key);
  +                prune(globalCache, key, delimiter);
  +                if (loggingEnabled) {
  +                    logger.log("Removed '" + key + "'", logChannel, Logger.DEBUG);
  +                }
  +            }
  +        }
  +    }
   
       public synchronized void start(Object txId) {
           if (txId != null) {
  @@ -284,6 +326,24 @@
                       + " / "
                       + (globalCache != null ? globalCache.size() : -1));
               logger.log(log.toString(), logChannel, Logger.DEBUG);
  +        }
  +    }
  +    
  +    protected void prune(Map map, Object key, String delimiter) {
  +        for (Iterator it = map.entrySet().iterator(); it.hasNext();) {
  +        	Map.Entry entry = (Map.Entry)it.next();
  +        	if (entry.getKey().toString().startsWith(key + delimiter)) {
  +        		it.remove();
  +        	}
  +        }
  +    }
  +    
  +    protected void deprune(Set set, Object key, String delimiter) {
  +        for (Iterator it = globalCache.entrySet().iterator(); it.hasNext();) {
  +        	Map.Entry entry = (Map.Entry)it.next();
  +        	if (entry.getKey().toString().startsWith(key + delimiter)) {
  +        		set.add(key);
  +        	}
           }
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org