001 package railo.runtime.cache; 002 003 import railo.commons.io.cache.Cache; 004 import railo.commons.io.cache.CacheEntry; 005 import railo.runtime.type.Struct; 006 import railo.runtime.type.StructImpl; 007 import railo.runtime.type.dt.TimeSpan; 008 import railo.runtime.type.dt.TimeSpanImpl; 009 010 public class CacheUtil { 011 012 public static Struct getInfo(CacheEntry ce) { 013 Struct info=new StructImpl(); 014 info.setEL("key", ce.getKey()); 015 info.setEL("created", ce.created()); 016 info.setEL("last_hit", ce.lastHit()); 017 info.setEL("last_modified", ce.lastModified()); 018 019 info.setEL("hit_count", new Double(ce.hitCount())); 020 info.setEL("size", new Double(ce.size())); 021 022 023 info.setEL("idle_time_span", toTimespan(ce.idleTimeSpan())); 024 info.setEL("live_time_span", toTimespan(ce.liveTimeSpan())); 025 026 027 return info; 028 } 029 030 031 public static Struct getInfo(Cache c) { 032 Struct info=new StructImpl(); 033 034 long value = c.hitCount(); 035 if(value>=0)info.setEL("hit_count", new Double(value)); 036 value = c.missCount(); 037 if(value>=0)info.setEL("miss_count", new Double(value)); 038 039 return info; 040 } 041 042 043 public static Object toTimespan(long timespan) { 044 if(timespan==0)return ""; 045 046 TimeSpan ts = TimeSpanImpl.fromMillis(timespan); 047 if(ts==null)return ""; 048 return ts; 049 } 050 051 052 public static String toString(CacheEntry ce) { 053 054 return "created: "+ce.created() 055 +"\nlast-hit: "+ce.lastHit() 056 +"\nlast-modified: "+ce.lastModified() 057 058 +"\nidle-time: "+ce.idleTimeSpan() 059 +"\nlive-time :"+ce.liveTimeSpan() 060 061 +"\nhit-count: "+ce.hitCount() 062 +"\nsize: "+ce.size(); 063 } 064 065 066 067 068 069 070 071 }