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.PageException; 009 import railo.runtime.ext.function.Function; 010 import railo.runtime.op.Caster; 011 012 /** 013 * 014 */ 015 public final class CacheGet implements Function { 016 017 private static final long serialVersionUID = -7164470356423036571L; 018 019 public static Object call(PageContext pc, String key) throws PageException { 020 return call(pc, key,false, null); 021 } 022 023 public static Object call(PageContext pc, String key, boolean throwWhenNotExist) throws PageException { 024 return call(pc, key,throwWhenNotExist, null); 025 } 026 027 public static Object call(PageContext pc, String key, boolean throwWhenNotExist,String cacheName) throws PageException { 028 try { 029 Cache cache = Util.getCache(pc.getConfig(),cacheName,ConfigImpl.CACHE_DEFAULT_OBJECT); 030 return throwWhenNotExist?cache.getValue(Util.key(key)):cache.getValue(Util.key(key),null); 031 } catch (IOException e) { 032 throw Caster.toPageException(e); 033 } 034 } 035 }