fixed up CacheKey with appropriate equals and hashCode methods,
authorjohn <john>
Fri, 18 Apr 2003 15:37:29 +0000 (15:37 +0000)
committerjohn <john>
Fri, 18 Apr 2003 15:37:29 +0000 (15:37 +0000)
and set the MRUCache and OpenIndy to use CacheKey's instead of hackish String keys

also changed logger.warn to logger.info for the cache timing statements.

source/mircoders/global/CacheKey.java
source/mircoders/global/MRUCache.java
source/mircoders/servlet/ServletModuleOpenIndy.java

index 30b7e21..0e10fc8 100755 (executable)
@@ -40,8 +40,15 @@ public class CacheKey {
     type=theType;
     selector=theSelector;
   }
-  public boolean equals(CacheKey aCacheKey){
-    if (aCacheKey.type.equals(type) && aCacheKey.selector.equals(selector))
+  
+  public int hashCode(){
+    return type.hashCode()+selector.hashCode();
+  }
+
+  public boolean equals(Object aCacheKey){
+    if (!(aCacheKey instanceof CacheKey)) 
+      return false;
+    if (((CacheKey) aCacheKey).type.equals(type) && ((CacheKey) aCacheKey).selector.equals(selector))
       return true;
     else
       return false;
index 8e8a415..f0c1a4e 100755 (executable)
@@ -72,6 +72,7 @@ public class MRUCache {
 \r
   public boolean hasObject(CacheKey aCacheKey) {\r
     synchronized (cache) {\r
+      logger.info("MRUCache was this big : "+ mruList.size());\r
       return cache.containsKey(aCacheKey);\r
     }\r
   }\r
@@ -90,7 +91,7 @@ public class MRUCache {
       if (! hasObject(aCacheKey)){\r
        // add to the cache\r
        cache.put(aCacheKey,data);\r
-       if (mruList.size() > cacheMaxItems){\r
+       if (mruList.size() >= cacheMaxItems){\r
          removeObject((CacheKey) mruList.getLast());\r
        }\r
       }\r
index 55675b1..e0e70d9 100755 (executable)
@@ -94,7 +94,7 @@ import mir.util.HTTPRequestParser;
 import mir.util.StringRoutines;\r
 import mircoders.entity.EntityComment;\r
 import mircoders.entity.EntityContent;\r
-//import mircoders.global.CacheKey;\r
+import mircoders.global.CacheKey;\r
 import mircoders.global.MirGlobal;\r
 import mircoders.media.*;\r
 import mircoders.media.UnsupportedMediaFormatExc;\r
@@ -127,7 +127,7 @@ import mircoders.storage.DatabaseTopics;
  *    open-postings to the newswire\r
  *\r
  * @author mir-coders group\r
- * @version $Id: ServletModuleOpenIndy.java,v 1.76 2003/04/18 14:54:54 john Exp $\r
+ * @version $Id: ServletModuleOpenIndy.java,v 1.77 2003/04/18 15:37:29 john Exp $\r
  *\r
  */\r
 \r
@@ -1105,16 +1105,16 @@ public class ServletModuleOpenIndy extends ServletModule
          \r
          String cacheType="pdf";\r
          \r
-         String theCacheKey = cacheType+":"+cacheSelector;\r
+         CacheKey theCacheKey = new CacheKey(cacheType,cacheSelector);\r
          \r
          byte[] thePDF;\r
          \r
          if (MirGlobal.mruCache().hasObject(theCacheKey)){\r
-           logger.warn("fetching pdf from cache");\r
+           logger.info("fetching pdf from cache");\r
            thePDF = (byte[]) MirGlobal.mruCache().getObject(theCacheKey);\r
          }\r
          else {\r
-           logger.warn("generating pdf and caching it");\r
+           logger.info("generating pdf and caching it");\r
            ByteArrayOutputStream out = new ByteArrayOutputStream();\r
            PDFGenerator pdfMaker = new PDFGenerator(out);\r
            \r
@@ -1148,7 +1148,7 @@ public class ServletModuleOpenIndy extends ServletModule
          res.getOutputStream().write(thePDF);\r
          res.getOutputStream().flush();\r
          String elapsedtime=(new Long(System.currentTimeMillis()-starttime)).toString();\r
-         logger.warn("pdf retireval took "+elapsedtime + " milliseconds"  );\r
+         logger.info("pdf retireval took "+elapsedtime + " milliseconds"  );\r
 \r
         }\r
         else {\r