jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1166171 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk: store/PersistenceManager.java util/SimpleLRUCache.java util/SmallLRUCache.java
Date Wed, 07 Sep 2011 13:35:56 GMT
Author: stefan
Date: Wed Sep  7 13:35:55 2011
New Revision: 1166171

URL: http://svn.apache.org/viewvc?rev=1166171&view=rev
Log:
some refactoring: extracting blob handling interface from loose object store interface

oops...

Added:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/SimpleLRUCache.java
      - copied, changed from r1165228, jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/SmallLRUCache.java
Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistenceManager.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/SmallLRUCache.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistenceManager.java?rev=1166171&r1=1166170&r2=1166171&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistenceManager.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistenceManager.java
Wed Sep  7 13:35:55 2011
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.mk.store;
 
 import org.apache.jackrabbit.mk.blobs.BlobStore;
+import org.apache.jackrabbit.mk.util.SimpleLRUCache;
 
 import java.io.InputStream;
 import java.util.concurrent.locks.ReentrantLock;
@@ -31,6 +32,8 @@ public class PersistenceManager {
     RevisionStore revStore;
     BlobStore blobStore;
 
+    SimpleLRUCache cache;
+
     public void initialize(RevisionStore revs, BlobStore blobs) throws Exception {
         if (initialized) {
             throw new IllegalStateException("already initialized");
@@ -39,6 +42,8 @@ public class PersistenceManager {
         revStore = revs;
         blobStore = blobs;
 
+        cache = SimpleLRUCache.newInstance(10000);
+
         // make sure we've got a HEAD commit
         String head = revStore.getHeadId();
         if (head == null || head.length() == 0) {
@@ -58,6 +63,9 @@ public class PersistenceManager {
         }
         revStore.close();
         revStore = null;
+
+        cache.clear();
+
         initialized = false;
     }
 
@@ -66,7 +74,15 @@ public class PersistenceManager {
             throw new IllegalStateException("not initialized");
         }
 
-        return Node.fromBytes(id, revStore.get(id));
+        Node node = (Node) cache.get(id);
+        if (node != null) {
+            return node;
+        }
+
+        node = Node.fromBytes(id, revStore.get(id));
+        cache.put(id, node);
+
+        return node;
     }
 
     public String putNode(MutableNode node) throws Exception {
@@ -82,7 +98,15 @@ public class PersistenceManager {
             throw new IllegalStateException("not initialized");
         }
 
-        return Commit.fromBytes(id, revStore.get(id));
+        Commit commit = (Commit) cache.get(id);
+        if (commit != null) {
+            return commit;
+        }
+
+        commit = Commit.fromBytes(id, revStore.get(id));
+        cache.put(id, commit);
+
+        return commit;
     }
 
     public String putCommit(MutableCommit commit) throws Exception {

Copied: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/SimpleLRUCache.java
(from r1165228, jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/SmallLRUCache.java)
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/SimpleLRUCache.java?p2=jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/SimpleLRUCache.java&p1=jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/SmallLRUCache.java&r1=1165228&r2=1166171&rev=1166171&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/SmallLRUCache.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/SimpleLRUCache.java
Wed Sep  7 13:35:55 2011
@@ -25,12 +25,12 @@ import java.util.Map;
  * @param <K> the key
  * @param <V> the value
  */
-public class SmallLRUCache<K, V> extends LinkedHashMap<K, V> {
+public class SimpleLRUCache<K, V> extends LinkedHashMap<K, V> {
 
     private static final long serialVersionUID = 1L;
     private int size;
 
-    private SmallLRUCache(int size) {
+    private SimpleLRUCache(int size) {
         super(size, (float) 0.75, true);
         this.size = size;
     }
@@ -43,8 +43,8 @@ public class SmallLRUCache<K, V> extends
      * @param size the number of elements
      * @return the object
      */
-    public static <K, V> SmallLRUCache<K, V> newInstance(int size) {
-        return new SmallLRUCache<K, V>(size);
+    public static <K, V> SimpleLRUCache<K, V> newInstance(int size) {
+        return new SimpleLRUCache<K, V>(size);
     }
 
     public void setMaxSize(int size) {



Mime
View raw message