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,...]}".<br> 33 * For example: 34 * {@code org.apache.opencmis.client.bindings.cache.impl.MapCacheLevelImpl capacity=10} 35 * </p> 36 * 37 * @see CacheLevel 38 */ 39 public interface Cache extends Serializable { 40 41 /** 42 * Initializes the cache. 43 * 44 * @param cacheLevelConfig 45 * the level configuration strings from the root to the leafs 46 */ 47 void initialize(String[] cacheLevelConfig); 48 49 /** 50 * Adds an object to the cache. 51 * 52 * @param value 53 * the object 54 * @param keys 55 * the keys for this object 56 */ 57 void put(Object value, String... keys); 58 59 /** 60 * Retrieves an object from the cache. 61 * 62 * @param keys 63 * the keys 64 * @return the object or <code>null</code> if the branch or leaf doesn't 65 * exist 66 */ 67 Object get(String... keys); 68 69 /** 70 * Removes a branch or leaf from the cache. 71 * 72 * @param keys 73 * the keys of the branch or leaf 74 */ 75 void remove(String... keys); 76 77 /** 78 * Removes all entries from the cache. 79 */ 80 void removeAll(); 81 82 /** 83 * Checks if a given key is in the cache. 84 * 85 * @param keys 86 * the keys of the branch or leaf 87 * 88 * @return the index of the first key part that is not in the cache or 89 * {@code keys.length} if the object is in the cache 90 */ 91 int check(String... keys); 92 93 /** 94 * Applies a write lock. 95 */ 96 void writeLock(); 97 98 /** 99 * Releases a write lock. 100 */ 101 void writeUnlock(); 102 }