1 10 package org.mmbase.cache; 11 12 import org.mmbase.util.logging.*; 13 14 22 public abstract class BlobCache extends Cache { 23 24 private static final Logger log = Logging.getLoggerInstance(BlobCache.class); 25 26 public BlobCache(int size) { 27 super(size); 28 } 29 30 protected int getDefaultMaxEntrySize() { 31 return 100 * 1024; 32 33 } 34 35 public String getName() { 36 return "A Blob Cache"; 37 } 38 39 public String getDescription() { 40 return "Node number - field Name-> ByteArray"; 41 } 42 43 public final String getKey(int nodeNumber, String fieldName) { 44 return "" + nodeNumber + '-' + fieldName; 45 } 46 47 public Object put(Object key, Object value) { 48 if (!checkCachePolicy(key)) return null; 49 if (value instanceof byte[]) { 50 int max = getMaxEntrySize(); 51 byte[] b = (byte[]) value; 52 log.trace(" max " + max + " " + b.length); 53 if (max > 0 && b.length > max) return null; 54 } else if (value instanceof String ) { 55 int max = getMaxEntrySize(); 56 String s = (String ) value; 57 if (max > 0 && s.length() > getMaxEntrySize()) return null; 58 } 59 return super.put(key, value); 60 } 61 62 63 } 64 | Popular Tags |