01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (http://h2database.com/html/license.html).
04: * Initial Developer: H2 Group
05: */
06: package org.h2.util;
07:
08: import java.sql.SQLException;
09:
10: /**
11: * The cache keeps frequently used objects in the main memory.
12: */
13: public interface Cache {
14:
15: /**
16: * Get all objects in the cache that have been changed.
17: *
18: * @return the list of objects
19: */
20: ObjectArray getAllChanged();
21:
22: /**
23: * Clear the cache.
24: */
25: void clear();
26:
27: /**
28: * Get an element in the cache if it is available.
29: * This will move the item to the front of the list.
30: *
31: * @param pos the unique key of the element
32: * @return the element or null
33: */
34: CacheObject get(int pos);
35:
36: /**
37: * Add an element to the cache. Other items may fall out of the cache
38: * because of this. It is not allowed to add the same record twice.
39: *
40: * @param r the object
41: */
42: void put(CacheObject r) throws SQLException;
43:
44: /**
45: * Update an element in the cache.
46: * This will move the item to the front of the list.
47: *
48: * @param pos the unique key of the element
49: * @param record the element
50: * @return the element
51: */
52: CacheObject update(int pos, CacheObject record) throws SQLException;
53:
54: /**
55: * Remove an object from the cache.
56: *
57: * @param pos the unique key of the element
58: */
59: void remove(int pos);
60:
61: /**
62: * Get an element from the cache if it is available.
63: * This will not move the item to the front of the list.
64: *
65: * @param pos the unique key of the element
66: * @return the element or null
67: */
68: CacheObject find(int pos);
69:
70: /**
71: * Set the maximum memory to be used by this cache.
72: *
73: * @param memorySize in number of double words (4 bytes)
74: */
75: void setMaxSize(int memorySize) throws SQLException;
76:
77: /**
78: * Get the name of the cache type in a human readable form.
79: *
80: * @return the cache type name
81: */
82: String getTypeName();
83: }
|