KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > cache > BlobCache


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.cache;
11
12 import org.mmbase.util.logging.*;
13
14 /**
15  * The 'blob cache' is used in MMObjectNode to cache small byte-array field values. it is a
16  * replacement for the 'handle cache' which was present in MMBase <1.8.
17  *
18  * @author Michiel Meeuwissen
19  * @version $Id: BlobCache.java,v 1.4 2005/07/09 11:10:09 nklasens Exp $
20  * @since MMBase 1.8
21  */

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 JavaDoc getName() {
36         return "A Blob Cache";
37     }
38
39     public String JavaDoc getDescription() {
40         return "Node number - field Name-> ByteArray";
41     }
42
43     public final String JavaDoc getKey(int nodeNumber, String JavaDoc fieldName) {
44         return "" + nodeNumber + '-' + fieldName;
45     }
46
47     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc 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 JavaDoc) {
55             int max = getMaxEntrySize();
56             String JavaDoc s = (String JavaDoc) value;
57             if (max > 0 && s.length() > getMaxEntrySize()) return null;
58         }
59         return super.put(key, value);
60     }
61
62
63 }
64
Popular Tags