| 1 |
/* |
| 2 |
* Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, |
| 3 |
* and the EPL 1.0 (https://h2database.com/html/license.html). |
| 4 |
* Initial Developer: H2 Group |
| 5 |
*/ |
| 6 |
package org.h2.util; |
| 7 |
|
| 8 |
import java.util.ArrayList; |
| 9 |
|
| 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 |
ArrayList<CacheObject> 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); |
| 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); |
| 53 |
|
| 54 |
/** |
| 55 |
* Remove an object from the cache. |
| 56 |
* |
| 57 |
* @param pos the unique key of the element |
| 58 |
* @return true if the key was in the cache |
| 59 |
*/ |
| 60 |
boolean remove(int pos); |
| 61 |
|
| 62 |
/** |
| 63 |
* Get an element from the cache if it is available. |
| 64 |
* This will not move the item to the front of the list. |
| 65 |
* |
| 66 |
* @param pos the unique key of the element |
| 67 |
* @return the element or null |
| 68 |
*/ |
| 69 |
CacheObject find(int pos); |
| 70 |
|
| 71 |
/** |
| 72 |
* Set the maximum memory to be used by this cache. |
| 73 |
* |
| 74 |
* @param size the maximum size in KB |
| 75 |
*/ |
| 76 |
void setMaxMemory(int size); |
| 77 |
|
| 78 |
/** |
| 79 |
* Get the maximum memory to be used. |
| 80 |
* |
| 81 |
* @return the maximum size in KB |
| 82 |
*/ |
| 83 |
int getMaxMemory(); |
| 84 |
|
| 85 |
/** |
| 86 |
* Get the used size in KB. |
| 87 |
* |
| 88 |
* @return the current size in KB |
| 89 |
*/ |
| 90 |
int getMemory(); |
| 91 |
|
| 92 |
} |