001/* 002 Licensed to the Apache Software Foundation (ASF) under one 003 or more contributor license agreements. See the NOTICE file 004 distributed with this work for additional information 005 regarding copyright ownership. The ASF licenses this file 006 to you under the Apache License, Version 2.0 (the 007 "License"); you may not use this file except in compliance 008 with the License. You may obtain a copy of the License at 009 010 http://www.apache.org/licenses/LICENSE-2.0 011 012 Unless required by applicable law or agreed to in writing, 013 software distributed under the License is distributed on an 014 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 KIND, either express or implied. See the License for the 016 specific language governing permissions and limitations 017 under the License. 018 */ 019package org.apache.wiki.cache; 020 021 022import org.apache.wiki.util.CheckedSupplier; 023 024import java.io.Serializable; 025import java.util.List; 026 027/** 028 * Cache manager abstraction. 029 */ 030public interface CachingManager { 031 032 /** 033 * The property value for setting the cache on/off. Value is {@value}. 034 * This key is deprecated, use instead {@link #PROP_CACHE_ENABLE}. 035 */ 036 @Deprecated 037 String PROP_USECACHE_DEPRECATED = "jspwiki.usePageCache"; 038 039 /** The property value for setting the cache on/off. Value is {@value}. */ 040 String PROP_CACHE_ENABLE = "jspwiki.cache.enable"; 041 042 /** The property value with the location of the cache configuration file. Value is {@value}. */ 043 String PROP_CACHE_CONF_FILE = "jspwiki.cache.config-file"; 044 045 /** Name of the attachment cache. */ 046 String CACHE_ATTACHMENTS = "jspwiki.attachmentsCache"; 047 048 /** Name of the collection attachment cache. */ 049 String CACHE_ATTACHMENTS_COLLECTION = "jspwiki.attachmentCollectionsCache"; 050 051 /** Name of the dynamic attachment cache. */ 052 String CACHE_ATTACHMENTS_DYNAMIC = "jspwiki.dynamicAttachmentCache"; 053 054 /** Name of the page cache. */ 055 String CACHE_PAGES = "jspwiki.pageCache"; 056 057 /** Name of the page text cache. */ 058 String CACHE_PAGES_TEXT = "jspwiki.pageTextCache"; 059 060 /** Name of the page history cache. */ 061 String CACHE_PAGES_HISTORY = "jspwiki.pageHistoryCache"; 062 063 /** Name of the rendering cache. */ 064 String CACHE_DOCUMENTS = "jspwiki.renderingCache"; 065 066 /** 067 * Shuts down the underlying cache manager 068 */ 069 void shutdown(); 070 071 /** 072 * Checks if the requested cache is enabled or not. 073 * 074 * @param cacheName The cache to be queried. 075 * @return {@code true} if the cache is enabled, {@code false} otherwise. 076 */ 077 boolean enabled( String cacheName ); 078 079 /** 080 * Retrieves cache usage information. 081 * 082 * @param cacheName The cache to be queried. 083 * @return cache usage information, or {@code null} if the requested cache is not enabled. 084 */ 085 CacheInfo info( String cacheName ); 086 087 /** 088 * Returns the list of keys from elements present in a cache. 089 * 090 * @param cacheName The cache to be queried. 091 * @return list of keys from elements present in a cache. 092 */ 093 < T extends Serializable > List< T > keys( String cacheName ); 094 095 /** 096 * Returns an item from a cache. If it is not found on the cache, try to retrieve from the provided supplier. If 097 * found there, put the value in the cache, and return it. Otherwise, return {@code null}. 098 * 099 * @param cacheName The cache in which the item lives. 100 * @param key item's identifier. 101 * @param supplier if the element is not cached, try to retrieve from the cached system. 102 * @throws E the supplier may throw a checked exception, which is propagated upwards. 103 * @return The requested item or {@code null} if either the cache is not enabled or the item is not present on the cache / cached service. 104 */ 105 < T, E extends Exception > T get( String cacheName, Serializable key, CheckedSupplier< T, E > supplier ) throws E; 106 107 /** 108 * Puts an item on a cache. 109 * 110 * @param cacheName The cache in which the item will live. 111 * @param key item's identifier. 112 * @param val item to insert in the cache. 113 */ 114 void put( String cacheName, Serializable key, Object val ); 115 116 /** 117 * Removes an item from a cache. 118 * 119 * @param cacheName The cache in which the item to be removed lives. 120 * @param key item's identifier. 121 */ 122 void remove( String cacheName, Serializable key ); 123 124}