001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.cache.eh; 020 021import java.util.Date; 022 023import lucee.commons.io.cache.CacheEntry; 024import lucee.runtime.cache.CacheUtil; 025import lucee.runtime.type.Struct; 026import net.sf.ehcache.Element; 027 028public class EHCacheEntry implements CacheEntry { 029 030 private Element element; 031 032 public EHCacheEntry(Element element) { 033 this.element=element; 034 } 035 036 @Override 037 public Date created() { 038 return new Date(element.getCreationTime()); 039 } 040 041 @Override 042 public Date lastHit() { 043 return new Date(element.getLastAccessTime()); 044 } 045 046 @Override 047 public Date lastModified() { 048 long value = element.getLastUpdateTime(); 049 if(value==0)return created(); 050 return new Date(value); 051 } 052 053 @Override 054 public int hitCount() { 055 return (int)element.getHitCount(); 056 } 057 058 @Override 059 public long idleTimeSpan() { 060 return element.getTimeToIdle()*1000; 061 } 062 063 @Override 064 public long liveTimeSpan() { 065 return element.getTimeToLive()*1000; 066 } 067 068 @Override 069 public long size() { 070 return element.getSerializedSize(); 071 } 072 073 @Override 074 public String getKey() { 075 return (String) element.getKey(); 076 } 077 078 @Override 079 public Object getValue() { 080 return element.getObjectValue(); 081 } 082 083 public void setElement(Element element) { 084 this.element=element; 085 } 086 087 088 @Override 089 public String toString() { 090 return CacheUtil.toString(this); 091 } 092 093 @Override 094 public Struct getCustomInfo() { 095 Struct info=CacheUtil.getInfo(this); 096 info.setEL("version", new Double(element.getVersion())); 097 return info; 098 } 099}