001    package railo.runtime.functions.cache;
002    
003    import railo.commons.io.cache.CacheKeyFilter;
004    import railo.runtime.PageContext;
005    import railo.runtime.cache.util.WildCardFilter;
006    import railo.runtime.config.ConfigImpl;
007    import railo.runtime.exp.PageException;
008    import railo.runtime.ext.function.Function;
009    import railo.runtime.op.Caster;
010    
011    /**
012     * 
013     */
014    public final class CacheClear implements Function,CacheKeyFilter {
015            
016            private static CacheKeyFilter filter=new CacheClear();
017    
018            public static double call(PageContext pc) throws PageException {
019                    return call(pc,null,null);
020                    
021            }
022            public static double call(PageContext pc,String strFilter) throws PageException {
023                    return call(pc,strFilter,null);
024                    
025            }
026            public static double call(PageContext pc,String strFilter, String cacheName) throws PageException {
027                    try {
028                            CacheKeyFilter f=filter;
029                            if(CacheGetAllIds.isFilter(strFilter))
030                                    f=new WildCardFilter(strFilter,true);
031                            return Util.getCache(pc.getConfig(),cacheName,ConfigImpl.CACHE_DEFAULT_OBJECT).remove(f);
032                    } catch (Exception e) {
033                            throw Caster.toPageException(e);
034                    }
035            }
036    
037            public boolean accept(String key) {
038                    return true;
039            }
040    
041            public String toPattern() {
042                    return "*";
043            }
044            
045    }