001 package railo.runtime.functions.cache; 002 003 import java.io.IOException; 004 005 import railo.commons.io.cache.Cache; 006 import railo.runtime.PageContext; 007 import railo.runtime.config.ConfigImpl; 008 import railo.runtime.exp.ApplicationException; 009 import railo.runtime.exp.PageException; 010 import railo.runtime.ext.function.Function; 011 import railo.runtime.op.Caster; 012 013 /** 014 * 015 */ 016 public final class CacheDelete implements Function { 017 018 private static final long serialVersionUID = 4148677299207997607L; 019 020 public static String call(PageContext pc, String id) throws PageException { 021 return call(pc, id, false,null); 022 } 023 public static String call(PageContext pc, String id, boolean throwOnError) throws PageException { 024 return call(pc, id, throwOnError, null); 025 } 026 027 public static String call(PageContext pc, String id, boolean throwOnError, String cacheName) throws PageException { 028 try { 029 Cache cache = Util.getCache(pc,cacheName,ConfigImpl.CACHE_DEFAULT_OBJECT); 030 if(!cache.remove(Util.key(id)) && throwOnError){ 031 throw new ApplicationException("can not remove the element with the following id ["+id+"]"); 032 } 033 } 034 catch (IOException e) { 035 throw Caster.toPageException(e); 036 } 037 return null; 038 } 039 040 }