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.ram; 020 021import java.util.Date; 022 023import lucee.commons.io.cache.CacheEntry; 024import lucee.runtime.cache.CacheUtil; 025import lucee.runtime.type.Struct; 026 027public class RamCacheEntry implements CacheEntry { 028 029 private String key; 030 private Object value; 031 private long idleTime; 032 private long until; 033 private long created; 034 private long modifed; 035 private long accessed; 036 private int hitCount; 037 038 public RamCacheEntry(String key, Object value, long idleTime, long until) { 039 this.key=key; 040 this.value=value; 041 this.idleTime=idleTime; 042 this.until=until; 043 created=modifed=accessed=System.currentTimeMillis(); 044 hitCount=1; 045 } 046 047 @Override 048 public Date created() { 049 return new Date(created); 050 } 051 052 @Override 053 public Struct getCustomInfo() { 054 return CacheUtil.getInfo(this); 055 } 056 057 @Override 058 public String getKey() { 059 return key; 060 } 061 062 @Override 063 public Object getValue() { 064 return value; 065 } 066 067 @Override 068 public int hitCount() { 069 return hitCount; 070 } 071 072 @Override 073 public long idleTimeSpan() { 074 return idleTime; 075 } 076 077 @Override 078 public Date lastHit() { 079 return new Date(accessed); 080 } 081 082 @Override 083 public Date lastModified() { 084 return new Date(modifed); 085 } 086 087 @Override 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}