001 package railo.runtime.cache.eh; 002 003 import java.util.Date; 004 005 import net.sf.ehcache.Element; 006 import railo.commons.io.cache.CacheEntry; 007 import railo.runtime.cache.CacheUtil; 008 import railo.runtime.type.Struct; 009 010 public class EHCacheEntry implements CacheEntry { 011 012 private Element element; 013 014 public EHCacheEntry(Element element) { 015 this.element=element; 016 } 017 018 /** 019 * @see railo.commons.io.cache.CacheEntry#created() 020 */ 021 public Date created() { 022 return new Date(element.getCreationTime()); 023 } 024 025 /** 026 * @see railo.commons.io.cache.CacheEntry#lastHit() 027 */ 028 public Date lastHit() { 029 return new Date(element.getLastAccessTime()); 030 } 031 032 /** 033 * @see railo.commons.io.cache.CacheEntry#lastModified() 034 */ 035 public Date lastModified() { 036 long value = element.getLastUpdateTime(); 037 if(value==0)return created(); 038 return new Date(value); 039 } 040 041 /** 042 * @see railo.commons.io.cache.CacheEntry#hitCount() 043 */ 044 public int hitCount() { 045 return (int)element.getHitCount(); 046 } 047 048 /** 049 * @see railo.commons.io.cache.CacheEntry#idleTimeSpan() 050 */ 051 public long idleTimeSpan() { 052 return element.getTimeToIdle()*1000; 053 } 054 055 /** 056 * @see railo.commons.io.cache.CacheEntry#validUntil() 057 */ 058 public long liveTimeSpan() { 059 return element.getTimeToLive()*1000; 060 } 061 062 /** 063 * @see railo.commons.io.cache.CacheEntry#size() 064 */ 065 public long size() { 066 return element.getSerializedSize(); 067 } 068 069 /** 070 * @see railo.commons.io.cache.CacheEntry#getKey() 071 */ 072 public String getKey() { 073 return (String) element.getKey(); 074 } 075 076 /** 077 * @see railo.commons.io.cache.CacheEntry#getValue() 078 */ 079 public Object getValue() { 080 return element.getObjectValue(); 081 } 082 083 public void setElement(Element element) { 084 this.element=element; 085 } 086 087 088 /** 089 * @see java.lang.Object#toString() 090 */ 091 public String toString() { 092 return CacheUtil.toString(this); 093 } 094 095 /** 096 * @see railo.commons.io.cache.CacheEntry#getCusomInfo() 097 */ 098 public Struct getCustomInfo() { 099 Struct info=CacheUtil.getInfo(this); 100 info.setEL("version", new Double(element.getVersion())); 101 return info; 102 } 103 }