01: /* Cache.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Thu Sep 6 15:35:06 2007, Created by tomyeh
10: }}IS_NOTE
11:
12: Copyright (C) 2007 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.util;
20:
21: /**
22: * Represents a cache.
23: * The interface is similar to java.util.Map but simpler to implement.
24: *
25: * @author tomyeh
26: * @since 3.0.0
27: */
28: public interface Cache {
29: /** Returns whether the specified key is stored.
30: */
31: public boolean containsKey(Object key);
32:
33: /** Returns the object of the specified key, or null if not found.
34: */
35: public Object get(Object key);
36:
37: /** Stores an object to the cache.
38: * @return the previous value of the same, or null if no such value
39: */
40: public Object put(Object key, Object value);
41:
42: /** Removes an object from the cache.
43: * @return the object if found.
44: */
45: public Object remove(Object key);
46:
47: /** Clears all objects being cached.
48: */
49: public void clear();
50:
51: //Control//
52: /** The default minimal lifetime, unit=milliseconds. It is 30 minutes. */
53: public static final int DEFAULT_LIFETIME = 30 * 60 * 1000;
54: /** The default maximal allowed size. It is 512. */
55: public static final int DEFAULT_MAX_SIZE = 512;
56:
57: /**
58: * Returns the minimal lifetime, unit=milliseconds.
59: * An mapping won't be removed by GC unless the minimal lifetime
60: * or the maximal allowed size exceeds.
61: * @see #getMaxSize
62: */
63: public int getLifetime();
64:
65: /**
66: * Sets the minimal lifetime. Default: {@link #DEFAULT_LIFETIME}.
67: *
68: * @param lifetime the lifetime, unit=milliseconds;
69: * if non-posive, they will be removed immediately.
70: * @see #getLifetime
71: */
72: public void setLifetime(int lifetime);
73:
74: /**
75: * Returns the maximal allowed size. Defalut: {@link #DEFAULT_MAX_SIZE}.
76: * An mapping won't be removed by GC unless the minimal lifetime
77: * or the maximal allowed size exceeds.
78: * @see #getLifetime
79: */
80: public int getMaxSize();
81:
82: /**
83: * Sets the maximal allowed size.
84: * @see #getMaxSize
85: */
86: public void setMaxSize(int maxsize);
87: }
|