/**
 *
 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either 
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public 
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 * 
 **/
package lucee.runtime.cache.ram;

import java.util.Date;

import lucee.commons.io.cache.CacheEntry;
import lucee.runtime.cache.CacheUtil;
import lucee.runtime.type.Struct;

public class RamCacheEntry implements CacheEntry {

	private String key;
	private Object value;
	private long idleTime;
	private long until;
	private long created;
	private long modifed;
	private long accessed;
	private int hitCount;

	public RamCacheEntry(String key, Object value, long idleTime, long until) {
		this.key=key;
		this.value=value;
		this.idleTime=idleTime;
		this.until=until;
		created=modifed=accessed=System.currentTimeMillis();
		hitCount=1;
	}

	@Override
	public Date created() {
		return new Date(created);
	}

	@Override
	public Struct getCustomInfo() {
		return CacheUtil.getInfo(this);
	}

	@Override
	public String getKey() {
		return key;
	}

	@Override
	public Object getValue() {
		return value;
	}

	@Override
	public int hitCount() {
		return hitCount;
	}

	@Override
	public long idleTimeSpan() {
		return idleTime;
	}

	@Override
	public Date lastHit() {
		return new Date(accessed);
	}

	@Override
	public Date lastModified() {
		return new Date(modifed);
	}

	@Override
	public long liveTimeSpan() {
		return until;
	}

	@Override
	public long size() {
		// TODO Auto-generated method stub
		return 0;
	}

	public void update(Object value) {
		this.value=value;
		modifed=accessed=System.currentTimeMillis();
		hitCount++;
	}

	public RamCacheEntry read() {
		accessed=System.currentTimeMillis();
		hitCount++;
		return this;
	}
}
@@ -802,19 +802,124 @@
 ava.
-util.Date;%0A
+io.ByteArrayOutputStream;%0Aimport java.io.ObjectOutputStream;%0Aimport java.util.Date;%0A%0Aimport lucee.commons.io.IOUtil;
 %0Aimp
@@ -2126,53 +2126,28 @@
 %7B%0A%09%09
-// TODO Auto-generated method stub%0A%09%09return 0
+return sizeOf(value)
 ;%0A%09%7D
@@ -2368,12 +2368,419 @@
 n this;%0A
-
 %09%7D%0A
+%09%0A%09private static int sizeOf(Object o) %7B%0A%09%09//System.err.println(o.getClass().getName());%0A%09%09ByteArrayOutputStream os = new ByteArrayOutputStream();%0A%09%09ObjectOutputStream oos=null;%0A        try %7B%0A%09        oos = new ObjectOutputStream(os);%0A%09        oos.writeObject(o);%0A        %7D%0A        catch(Throwable t)%7B%7D%0A        finally %7B%0A        %09IOUtil.closeEL(oos);%0A        %7D%0A        return os.toByteArray().length;%0A    %7D%0A
 %7D

add support for "size" to RamCacheEntry