All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.jackrabbit.spi.ItemInfoCache Maven / Gradle / Ivy

There is a newer version: 2.0.10
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.jackrabbit.spi;

/**
 * ItemInfoCache instances are responsible for caching
 * {@link ItemInfo}s along with an opaque generation counter. Implementations
 * are free on the particular caching policy. That is, how long (if at all) item
 * infos are cached.
 *
 * An ItemInfoCache is supplied per session from the {@link RepositoryService}. It is used
 * to cache ItemInfos read from the RepositoryService.
 *
 * @see RepositoryService#getItemInfos(SessionInfo, ItemId)
 */
public interface ItemInfoCache {

    /**
     * This class represents a cache entry.
     * @param  Either a {@link NodeInfo} or a {@link PropertyInfo}.
     */
    class Entry {

        /**
         * The {@link ItemInfo}
         */
        public final T info;

        /**
         * The generation
         */
        public final long generation;

        /**
         * Create a new cache entry containing info with a given generation.
         * @param info
         * @param generation
         */
        public Entry(T info, long generation) {
            this.info = info;
            this.generation = generation;
        }

        @Override
        public int hashCode() {
            return info.hashCode() + (int) generation;
        }

        @Override
        public boolean equals(Object that) {
            if (that == null) {
                return false;
            }

            if (that == this) {
                return true;
            }

            if (that instanceof ItemInfoCache.Entry) {
                ItemInfoCache.Entry other = (ItemInfoCache.Entry) that;
                return generation == other.generation && info.equals(other.info);
            }

            return false;
        }
    }

    /**
     * Retrieve a cache entry for the given nodeId or null
     * if no such entry is in the cache.
     *
     * @param nodeId  id of the entry to lookup.
     * @return a Entry<NodeInfo> instance or null
     * if not found.
     */
    ItemInfoCache.Entry getNodeInfo(NodeId nodeId);

    /**
     * Retrieve a cache entry for the given propertyId or null
     * if no such entry is in the cache.
     *
     * @param propertyId  id of the entry to lookup.
     * @return  a Entry<PropertyInfo> instance or
     * null if not found.
     */
    ItemInfoCache.Entry getPropertyInfo(PropertyId propertyId);

    /**
     * Create a {@link Entry} for info and generation and put it into
     * the cache.
     * @param info
     * @param generation
     */
    void put(ItemInfo info, long generation);

    /**
     * Clear the cache and dispose all entries.
     */
    void dispose();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy