001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019/** 020 * Implements the CFML Function gettemplatepath 021 */ 022package lucee.runtime.functions.system; 023 024import lucee.commons.lang.ExceptionUtil; 025import lucee.commons.lang.StringUtil; 026import lucee.runtime.PageContext; 027import lucee.runtime.config.ConfigWebImpl; 028import lucee.runtime.config.ConfigWebUtil; 029import lucee.runtime.exp.FunctionException; 030import lucee.runtime.exp.PageException; 031import lucee.runtime.ext.function.Function; 032import lucee.runtime.functions.component.ComponentCacheClear; 033import lucee.runtime.functions.other.CTCacheClear; 034import lucee.runtime.type.Collection; 035import lucee.runtime.type.KeyImpl; 036import lucee.runtime.type.util.KeyConstants; 037 038public final class SystemCacheClear implements Function { 039 040 private static final long serialVersionUID = 2151674703665027213L; 041 042 public static String call(PageContext pc) throws PageException { 043 return call(pc,null); 044 } 045 public static String call(PageContext pc, String cacheName) throws PageException { 046 047 if(StringUtil.isEmpty(cacheName,true) || "all".equals(cacheName=cacheName.trim().toLowerCase())) { 048 PagePoolClear.call(pc); 049 ComponentCacheClear.call(pc); 050 CTCacheClear.call(pc); 051 queryCache(pc); 052 tagCache(pc); 053 functionCache(pc); 054 } 055 else if("template".equals(cacheName) || "page".equals(cacheName)) { 056 PagePoolClear.call(pc); 057 } 058 else if("component".equals(cacheName) || "cfc".equals(cacheName)) { 059 ComponentCacheClear.call(pc); 060 } 061 else if("customtag".equals(cacheName) || "ct".equals(cacheName)) { 062 CTCacheClear.call(pc); 063 } 064 else if("query".equals(cacheName) || "object".equals(cacheName)) { 065 queryCache(pc); 066 } 067 else if("tag".equals(cacheName)) { 068 tagCache(pc); 069 } 070 else if("function".equals(cacheName)) { 071 functionCache(pc); 072 } 073 else 074 throw new FunctionException(pc, "cacheClear", 1, "cacheName", 075 ExceptionUtil.similarKeyMessage(new Collection.Key[]{ 076 KeyConstants._all, 077 KeyConstants._template, 078 KeyConstants._component, 079 KeyImpl.init("customtag"), 080 KeyConstants._query, 081 KeyConstants._tag, 082 KeyConstants._function}, cacheName, "cache name", "cache names",true)); 083 084 085 return null; 086 } 087 088 private static void queryCache(PageContext pc) throws PageException { 089 ConfigWebUtil.getCacheHandlerFactories(pc.getConfig()).query.clear(pc); 090 } 091 092 private static void tagCache(PageContext pc) { 093 ConfigWebImpl config=(ConfigWebImpl) pc.getConfig(); 094 PagePoolClear.clear(config.getServerTagMapping()); 095 PagePoolClear.clear(config.getTagMapping()); 096 } 097 098 private static void functionCache(PageContext pc) { 099 ConfigWebImpl config=(ConfigWebImpl) pc.getConfig(); 100 config.clearFunctionCache(); 101 PagePoolClear.clear(config.getServerFunctionMapping()); 102 PagePoolClear.clear(config.getFunctionMapping()); 103 } 104}