1 /* 2 * ModeShape (http://www.modeshape.org) 3 * See the COPYRIGHT.txt file distributed with this work for information 4 * regarding copyright ownership. Some portions may be licensed 5 * to Red Hat, Inc. under one or more contributor license agreements. 6 * See the AUTHORS.txt file in the distribution for a full listing of 7 * individual contributors. 8 * 9 * ModeShape is free software. Unless otherwise indicated, all code in ModeShape 10 * is licensed to you under the terms of the GNU Lesser General Public License as 11 * published by the Free Software Foundation; either version 2.1 of 12 * the License, or (at your option) any later version. 13 * 14 * ModeShape is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * Lesser General Public License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public 20 * License along with this software; if not, write to the Free 21 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 22 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 23 */ 24 package org.modeshape.graph.connector.path.cache; 25 26 import net.jcip.annotations.ThreadSafe; 27 import org.modeshape.graph.connector.path.PathNode; 28 import org.modeshape.graph.property.Path; 29 30 /** 31 * The basic contract for a workspace-level cache of paths to the nodes stored at that path. 32 * <p> 33 * Implementations must provide a no-argument constructor in order to be instantiated by {@link PathRepositoryCache}. After 34 * instantiation, the {@link #initialize(PathCachePolicy, String)} method will be called to inject the cache policy into the 35 * implementation. 36 * </p> 37 * <p> 38 * Implementations must be thread-safe. 39 * </p> 40 */ 41 @ThreadSafe 42 public interface WorkspaceCache { 43 44 /** 45 * Injects the cache policy into the cache 46 * 47 * @param policy the active cache policy for the repository source with which this cache is associated 48 * @param workspaceName the name of the workspace that this cache is managing 49 * @throws IllegalStateException if this method is called on a cache that has already been initialized. 50 */ 51 public void initialize( PathCachePolicy policy, 52 String workspaceName ); 53 54 /** 55 * Clears all statistics for this cache 56 */ 57 public void clearStatistics(); 58 59 /** 60 * @return the statistics since the most recent of the cache initialization or the last call to {@link #clearStatistics()}; 61 * never null 62 */ 63 public CacheStatistics getStatistics(); 64 65 /** 66 * Retrieves the cached node with the given path, it it exists and is valid 67 * 68 * @param path the path for the node to be retrieved 69 * @return the cached node with the given path; may be null if no node with that path is cached or a node with that path is 70 * cached but is deemed invalid for implementation-specific reasons 71 */ 72 public PathNode get( Path path ); 73 74 /** 75 * Attempts to cache the given node. Implementations must call {@link PathCachePolicy#shouldCache(PathNode)} on the policy 76 * from the {@link #initialize(PathCachePolicy, String)} method to determine if the node should be cached. 77 * 78 * @param node the node that is to be cached; may not be null 79 */ 80 public void set( PathNode node ); 81 82 /** 83 * Invalidates all nodes in the cache that have the given path or have a path that is an ancestor of the given path 84 * 85 * @param path the root of the branch of nodes that are to be invalidated; may not be null 86 */ 87 public void invalidate( Path path ); 88 89 /** 90 * Indicates that the cache is no longer in use and should relinquish any resources. 91 */ 92 public void close(); 93 }