1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.chemistry.opencmis.client.bindings.cache;
20
21 import java.io.Serializable;
22
23 /**
24 * An interface for an hierarchical cache.
25 *
26 * <p>
27 * Each level of the hierarchy could use a different caching strategy. The cache
28 * is initialize by defining the classes that handle the caching for one level.
29 * These classes must implement the {@link CacheLevel} interface.<br/>
30 * <br/>
31 * Level configuration string format: "
32 * <code><class name> [param1=value1,param2=value2,...]</code>".<br/>
33 * For example:
34 * <code>org.apache.opencmis.client.bindings.cache.impl.MapCacheLevelImpl capacity=10</code>
35 * <br/>
36 * </p>
37 *
38 * @author <a href="mailto:fmueller@opentext.com">Florian Müller</a>
39 *
40 * @see CacheLevel
41 */
42 public interface Cache extends Serializable {
43
44 /**
45 * Initializes the cache.
46 *
47 * @param cacheLevelConfig
48 * the level configuration strings from the root to the leafs
49 */
50 void initialize(String[] cacheLevelConfig);
51
52 /**
53 * Adds an object to the cache.
54 *
55 * @param value
56 * the object
57 * @param keys
58 * the keys for this object
59 */
60 void put(Object value, String... keys);
61
62 /**
63 * Retrieves an object from the cache.
64 *
65 * @param keys
66 * the keys
67 * @return the object or <code>null<code> if the branch or leaf doesn't exist
68 */
69 Object get(String... keys);
70
71 /**
72 * Removes a branch or leaf from the cache.
73 *
74 * @param keys
75 * the keys of the branch or leaf
76 */
77 void remove(String... keys);
78
79 /**
80 * Checks if a given key is in the cache.
81 *
82 * @param keys
83 * the keys of the branch or leaf
84 *
85 * @return the index of the first key part that is not in the cache or
86 * <code>keys.length</code> if the object is in the cache
87 */
88 int check(String... keys);
89
90 /**
91 * Applies a write lock.
92 */
93 void writeLock();
94
95 /**
96 * Releases a write lock.
97 */
98 void writeUnlock();
99 }