001/*
002 *  Copyright 2012 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.web.cache.pageelement;
017
018import java.util.Set;
019
020import org.ametys.core.observation.Event;
021import org.ametys.web.repository.site.Site;
022
023/**
024 * Used by the event processing to know whether cached content should be kept or cleared.
025 */
026public interface PageElementCachePolicy
027{
028    /**
029     * Processing result.
030     */
031    public enum PolicyResult
032    {
033        /**
034         * The corresponding cache entry should be removed.
035         */
036        REMOVE,
037        /**
038         * The corresponding cache entry should be kept.
039         */
040        KEEP,
041        /**
042         * The processing could go deeper in the data to know more precisely what to do with the cache entry.
043         */
044        NEED_MORE_INFORMATION
045    }
046    
047    /**
048     * Returns the types of the associated page elements.
049     * @return the types of the associated page elements.
050     */
051    public Set<String> getPageElementTypes();
052    
053    /**
054     * First pass of event processing, at the type level.<br>
055     * Returning NEED_MORE_INFORMATION eventually leads to the second pass, which is more precise, and also depends on a particular element, but is more costly to compute.<br>
056     * Returning null means that this policy declares itself as not concerned by the current event.
057     * @param workspace the current JCR workspace.
058     * @param site the current site.
059     * @param pageElementType the page element type.
060     * @param event the current event.
061     * @return the policy result or null if this policy declares itself as not concerned.
062     */
063    public PolicyResult shouldClearCache(String workspace, Site site, String pageElementType, Event event);
064    
065    /**
066     * Second pass of event processing, at the Page level.<br>
067     * This method is only called if the first pass resulted with NEED_MORE_INFORMATION.
068     * If this method also returns NEED_MORE_INFORMATION, it will be interpreted as REMOVE.
069     * @param workspace the current JCR workspace.
070     * @param site the current site.
071     * @param pageElementType the page element type.
072     * @param elementId the current element id.
073     * @param event the current event.
074     * @return the policy result.
075     */
076    public PolicyResult shouldClearCache(String workspace, Site site, String pageElementType, String elementId, Event event);
077}