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.tag.udf;
020
021import java.io.Serializable;
022
023import lucee.commons.digest.HashUtil;
024import lucee.runtime.PageContext;
025import lucee.runtime.cache.tag.CacheItem;
026import lucee.runtime.dump.DumpData;
027import lucee.runtime.dump.DumpProperties;
028import lucee.runtime.dump.DumpTable;
029import lucee.runtime.dump.DumpUtil;
030import lucee.runtime.dump.Dumpable;
031import lucee.runtime.dump.SimpleDumpData;
032
033public class UDFCacheItem implements CacheItem, Serializable, Dumpable {
034
035        private static final long serialVersionUID = -3616023500492159529L;
036
037        public final String output;
038        public final Object returnValue;
039        private String udfName;
040        private String meta;
041        private long executionTimeNS;
042
043        private final long payload;
044
045        
046        public UDFCacheItem(String output, Object returnValue, String udfName, String meta, long executionTimeNS) {
047                this.output = output;
048                this.returnValue = returnValue;
049                this.udfName = udfName;
050                this.meta = meta;
051                this.executionTimeNS=executionTimeNS;
052                this.payload=lucee.commons.lang.SizeOf.size(returnValue)+output.length();
053        }
054
055        @Override
056        public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties properties) {
057                DumpTable table = new DumpTable("#669999","#ccffff","#000000");
058                table.setTitle("UDFCacheEntry");
059                table.appendRow(1,new SimpleDumpData("Return Value"),DumpUtil.toDumpData(returnValue, pageContext, maxlevel, properties));
060                table.appendRow(1,new SimpleDumpData("Output"),DumpUtil.toDumpData(new SimpleDumpData(output), pageContext, maxlevel, properties));
061                return table;
062        }
063        
064        public String toString(){
065                return output;
066        }
067
068        @Override
069        public String getHashFromValue() {
070                return Long.toString(HashUtil.create64BitHash(output+":"+UDFArgConverter.serialize(returnValue)));
071        }
072
073        @Override
074        public String getName() {
075                return udfName;
076        }
077
078        @Override
079        public long getPayload() {
080                return payload;
081        }
082
083        @Override
084        public String getMeta() {
085                return meta;
086        }
087
088        @Override
089        public long getExecutionTime() {
090                return executionTimeNS;
091        }
092
093}