01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
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.5 2006/09/04 12:53:51 michiel Exp $
20: * @since MMBase 1.8
21: */
22: public abstract class BlobCache extends Cache<String, Object> {
23:
24: private static final Logger log = Logging
25: .getLoggerInstance(BlobCache.class);
26:
27: public BlobCache(int size) {
28: super (size);
29: }
30:
31: protected int getDefaultMaxEntrySize() {
32: return 100 * 1024;
33:
34: }
35:
36: public String getName() {
37: return "A Blob Cache";
38: }
39:
40: public String getDescription() {
41: return "Node number - field Name-> ByteArray";
42: }
43:
44: public final String getKey(int nodeNumber, String fieldName) {
45: return "" + nodeNumber + '-' + fieldName;
46: }
47:
48: public Object put(String key, Object value) {
49: if (!checkCachePolicy(key))
50: return null;
51: if (value instanceof byte[]) {
52: int max = getMaxEntrySize();
53: byte[] b = (byte[]) value;
54: log.trace(" max " + max + " " + b.length);
55: if (max > 0 && b.length > max)
56: return null;
57: } else if (value instanceof String) {
58: int max = getMaxEntrySize();
59: String s = (String) value;
60: if (max > 0 && s.length() > getMaxEntrySize())
61: return null;
62: }
63: return super.put(key, value);
64: }
65:
66: }
|