001: /* ***** BEGIN LICENSE BLOCK *****
002: * Version: MPL 1.1
003: * The contents of this file are subject to the Mozilla Public License Version
004: * 1.1 (the "License"); you may not use this file except in compliance with
005: * the License. You may obtain a copy of the License at
006: * http://www.mozilla.org/MPL/
007: *
008: * Software distributed under the License is distributed on an "AS IS" basis,
009: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
010: * for the specific language governing rights and limitations under the
011: * License.
012: *
013: * The Original Code is Riot.
014: *
015: * The Initial Developer of the Original Code is
016: * Neteye GmbH.
017: * Portions created by the Initial Developer are Copyright (C) 2007
018: * the Initial Developer. All Rights Reserved.
019: *
020: * Contributor(s):
021: * Felix Gnass [fgnass at neteye dot de]
022: *
023: * ***** END LICENSE BLOCK ***** */
024: package org.riotfamily.components.cache;
025:
026: import java.util.Collection;
027: import java.util.Iterator;
028:
029: import javax.servlet.http.HttpServletRequest;
030:
031: import org.riotfamily.cachius.Cache;
032: import org.riotfamily.cachius.TaggingContext;
033: import org.riotfamily.components.config.component.Component;
034: import org.riotfamily.components.model.ComponentList;
035: import org.riotfamily.components.model.ComponentVersion;
036: import org.riotfamily.components.model.Location;
037: import org.riotfamily.components.model.VersionContainer;
038:
039: /**
040: * @author Felix Gnass [fgnass at neteye dot de]
041: * @since 6.5
042: */
043: public final class ComponentCacheUtils {
044:
045: private static String getContainerTag(VersionContainer container,
046: boolean editMode) {
047:
048: return VersionContainer.class.getName() + '#'
049: + container.getId() + (editMode ? "-preview" : "-live");
050: }
051:
052: public static void addContainerTags(HttpServletRequest request,
053: VersionContainer container, boolean editMode) {
054:
055: TaggingContext.tag(request,
056: getContainerTag(container, editMode));
057: }
058:
059: /**
060: * This method will invalidate both, the live and preview versions of the container.
061: */
062: public static void invalidateContainer(Cache cache,
063: VersionContainer container) {
064: cache.invalidateTaggedItems(getContainerTag(container, false));
065: cache.invalidateTaggedItems(getContainerTag(container, true));
066: }
067:
068: public static void invalidateContainer(Cache cache,
069: VersionContainer container, boolean editMode) {
070:
071: cache
072: .invalidateTaggedItems(getContainerTag(container,
073: editMode));
074: }
075:
076: public static void addListTags(HttpServletRequest request,
077: VersionContainer container) {
078:
079: ComponentList list = container.getList();
080: if (list != null) {
081: addListTags(request, list.getLocation());
082: }
083: }
084:
085: public static void addListTags(HttpServletRequest request,
086: Location location) {
087:
088: TaggingContext.tag(request, location.toString());
089: }
090:
091: public static void invalidateList(Cache cache, ComponentList list) {
092: cache.invalidateTaggedItems(list.getLocation().toString());
093: }
094:
095: public static void addComponentTags(HttpServletRequest request,
096: Component component, ComponentVersion version) {
097:
098: Collection tags = component.getCacheTags(version);
099: if (tags != null) {
100: Iterator it = tags.iterator();
101: while (it.hasNext()) {
102: String tag = (String) it.next();
103: TaggingContext.tag(request, tag);
104: }
105: }
106: }
107: }
|