1 /** 2 * This file Copyright (c) 2008-2011 Magnolia International 3 * Ltd. (http://www.magnolia-cms.com). All rights reserved. 4 * 5 * 6 * This file is dual-licensed under both the Magnolia 7 * Network Agreement and the GNU General Public License. 8 * You may elect to use one or the other of these licenses. 9 * 10 * This file is distributed in the hope that it will be 11 * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the 12 * implied warranty of MERCHANTABILITY or FITNESS FOR A 13 * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT. 14 * Redistribution, except as permitted by whichever of the GPL 15 * or MNA you select, is prohibited. 16 * 17 * 1. For the GPL license (GPL), you can redistribute and/or 18 * modify this file under the terms of the GNU General 19 * Public License, Version 3, as published by the Free Software 20 * Foundation. You should have received a copy of the GNU 21 * General Public License, Version 3 along with this program; 22 * if not, write to the Free Software Foundation, Inc., 51 23 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 24 * 25 * 2. For the Magnolia Network Agreement (MNA), this file 26 * and the accompanying materials are made available under the 27 * terms of the MNA which accompanies this distribution, and 28 * is available at http://www.magnolia-cms.com/mna.html 29 * 30 * Any modifications to this file must keep this entire header 31 * intact. 32 * 33 */ 34 package info.magnolia.module.cache; 35 36 import info.magnolia.cms.core.AggregationState; 37 38 /** 39 * The CachePolicy determines is a requested page should be cached, 40 * retrieved from the cache or not cached at all. 41 * It is called for every request and should thus also take care of 42 * any expiration policy - i.e if the page should be recached. 43 * 44 * The CacheFilter (or any other client component) can determine its 45 * behaviour based on the return CachePolicyResult, which holds both 46 * the behaviour to take and the cache key to use when appropriate. 47 * 48 * @author gjoseph 49 * @version $Revision: $ ($Author: $) 50 */ 51 public interface CachePolicy { 52 53 /** 54 * Implementations can chose whether to cache or not - but note that the 55 * aggregationState might not be completely populated. Every request should be 56 * cacheable, not only those processed through Magnolia's RenderingFilter. 57 */ 58 CachePolicyResult shouldCache(final Cache cache, final AggregationState aggregationState, final FlushPolicy flushPolicy); 59 60 /** 61 * Returns cache key for the given item or null if such key can't be obtained or policy doesn't want to share it. 62 * When using aggregationState, key is expected to be composed with aggregated request in mind and policy has to choose only 63 * one such key denoting item to return to the client, if such an item indeed exists and can be served. 64 * When not existing key might be used to store the cache entry. Since only one version of the content can be streamed back to 65 * the client, it makes sense to create only one cache entry for the such a key as well. 66 */ 67 Object retrieveCacheKey(final AggregationState aggregationState); 68 69 70 /** 71 * Returns cache keys for the given item or null if such keys can't be obtained or policy doesn't want to share it. Since in 72 * this case uuid is used to retrieve the cache key, it is quite possible that multiple different representations of the content 73 * denoted by uuid exist and all such keys should be returned leaving it up to requesting object to deal with such a multiplicity. 74 * Please note that returned keys might not be necessary multiple representations of the content denoted by provided uuid, but 75 * also quite possibly all the content deemed related or partially used to construct any of the returned cache keys. 76 */ 77 Object[] retrieveCacheKeys(final String uuid, final String repository); 78 79 /** 80 * Presists mapping between uuid and cache key in case the given cache policy implementation cares about such details. 81 */ 82 void persistCacheKey(String repo, String uuid, Object key); 83 84 /** 85 * Returns cache keys for the given item or null if such keys can't be obtained or policy doesn't want to share it. Since in 86 * this case uuid is used to retrieve the cache key, it is quite possible that multiple different representations of the content 87 * denoted by uuid exist and all such keys should be returned leaving it up to requesting object to deal with such a multiplicity. 88 * Please note that returned keys might not be necessary multiple representations of the content denoted by provided uuid, but 89 * also quite possibly all the content deemed related or partially used to construct any of the returned cache keys. 90 * At the call to this method, cache policy should not only return the keys associated with the uuid, but also remove all returned uuid-cahce key mappings. 91 */ 92 Object[] removeCacheKeys(String uuid, String repository); 93 }