001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.wicket.markup;
018
019import org.apache.wicket.MarkupContainer;
020
021/**
022 * Each Wicket application has a single IMarkupCache associated with it (see
023 * {@link org.apache.wicket.settings.MarkupSettings}). Via {@link MarkupFactory}
024 * the markup cache is used by every Component to get its associated
025 * markup stream.
026 * 
027 * @author Juergen Donnerstag
028 */
029public interface IMarkupCache
030{
031        /**
032         * Clear markup cache and force reload of all markup data
033         */
034        void clear();
035
036        /**
037         * Gets any (immutable) markup resource for the container or any of its parent classes (markup
038         * inheritance)
039         * 
040         * @param container
041         *            The original requesting markup container
042         * @param clazz
043         *            The class to get the associated markup for. If null, the container's class is
044         *            used, but it can be a parent class of the container as well (markup inheritance)
045         * @param enforceReload
046         *            The cache will be ignored and all, including inherited markup files, will be
047         *            reloaded. Whatever is in the cache, it will be ignored
048         * @return Markup resource
049         */
050        Markup getMarkup(final MarkupContainer container, final Class<?> clazz,
051                final boolean enforceReload);
052
053        /**
054         * Remove the markup associated with the cache key from the cache including all dependent
055         * markups (markup inheritance)
056         * 
057         * @see MarkupResourceStream#getCacheKey()
058         * 
059         * @param cacheKey
060         * @return The markup removed from the cache. Null, if nothing was found.
061         */
062        IMarkupFragment removeMarkup(final String cacheKey);
063
064        /**
065         * @return the number of elements currently in the cache.
066         */
067        int size();
068
069        /**
070         * Will be called by the application while shutting down. It allows the markup cache to cleanup
071         * if necessary.
072         */
073        void shutdown();
074}