001    package railo.runtime.cache.ram;
002    
003    import java.util.Date;
004    
005    import railo.commons.io.cache.CacheEntry;
006    import railo.runtime.cache.CacheUtil;
007    import railo.runtime.type.Struct;
008    
009    public class RamCacheEntry implements CacheEntry {
010    
011            private String key;
012            private Object value;
013            private long idleTime;
014            private long until;
015            private long created;
016            private long modifed;
017            private long accessed;
018            private int hitCount;
019    
020            public RamCacheEntry(String key, Object value, long idleTime, long until) {
021                    this.key=key;
022                    this.value=value;
023                    this.idleTime=idleTime;
024                    this.until=until;
025                    created=modifed=accessed=System.currentTimeMillis();
026                    hitCount=1;
027            }
028    
029            /**
030             * @see railo.commons.io.cache.CacheEntry#created()
031             */
032            public Date created() {
033                    return new Date(created);
034            }
035    
036            /**
037             * @see railo.commons.io.cache.CacheEntry#getCustomInfo()
038             */
039            public Struct getCustomInfo() {
040                    return CacheUtil.getInfo(this);
041            }
042    
043            /**
044             * @see railo.commons.io.cache.CacheEntry#getKey()
045             */
046            public String getKey() {
047                    return key;
048            }
049    
050            /**
051             * @see railo.commons.io.cache.CacheEntry#getValue()
052             */
053            public Object getValue() {
054                    return value;
055            }
056    
057            /**
058             * @see railo.commons.io.cache.CacheEntry#hitCount()
059             */
060            public int hitCount() {
061                    return hitCount;
062            }
063    
064            /**
065             * @see railo.commons.io.cache.CacheEntry#idleTimeSpan()
066             */
067            public long idleTimeSpan() {
068                    return idleTime;
069            }
070    
071            /**
072             * @see railo.commons.io.cache.CacheEntry#lastHit()
073             */
074            public Date lastHit() {
075                    return new Date(accessed);
076            }
077    
078            /**
079             * @see railo.commons.io.cache.CacheEntry#lastModified()
080             */
081            public Date lastModified() {
082                    return new Date(modifed);
083            }
084    
085            /**
086             * @see railo.commons.io.cache.CacheEntry#liveTimeSpan()
087             */
088            public long liveTimeSpan() {
089                    return until;
090            }
091    
092            public long size() {
093                    // TODO Auto-generated method stub
094                    return 0;
095            }
096    
097            public void update(Object value) {
098                    this.value=value;
099                    modifed=accessed=System.currentTimeMillis();
100                    hitCount++;
101            }
102    
103            public RamCacheEntry read() {
104                    accessed=System.currentTimeMillis();
105                    hitCount++;
106                    return this;
107            }
108    }