1 25 package org.ofbiz.base.util.cache; 26 27 import java.io.Serializable ; 28 29 import org.ofbiz.base.util.UtilObject; 30 31 37 public class CacheLine implements Serializable { 38 39 public static final String module = CacheLine.class.getName(); 40 41 public Object valueRef = null; 42 public long loadTime = 0; 43 public long expireTime = 0; 44 public boolean useSoftReference = false; 45 46 public CacheLine(Object value, boolean useSoftReference, long expireTime) { 47 if (useSoftReference) { 48 this.valueRef = new CacheSoftReference(value); 49 } else { 50 this.valueRef = value; 51 } 52 this.useSoftReference = useSoftReference; 53 this.expireTime = expireTime; 54 } 55 56 public CacheLine(Object value, boolean useSoftReference, long loadTime, long expireTime) { 57 this(value, useSoftReference, expireTime); 58 this.loadTime = loadTime; 59 } 60 61 public Object getValue() { 62 if (valueRef == null) return null; 63 if (useSoftReference) { 64 return ((CacheSoftReference) valueRef).get(); 65 } else { 66 return valueRef; 67 } 68 } 69 70 public boolean softReferenceCleared() { 71 if (!this.useSoftReference || valueRef == null) { 72 return false; 73 } else { 74 if (((CacheSoftReference) valueRef).get() == null) { 75 return true; 76 } else { 77 return false; 78 } 79 } 80 } 81 82 public void setUseSoftReference(boolean useSoftReference) { 83 if (this.useSoftReference != useSoftReference) { 84 synchronized (this) { 85 this.useSoftReference = useSoftReference; 86 if (useSoftReference) { 87 this.valueRef = new CacheSoftReference(this.valueRef); 88 } else { 89 this.valueRef = ((CacheSoftReference) this.valueRef).get(); 90 } 91 } 92 } 93 } 94 95 public long getExpireTime() { 96 return this.expireTime; 97 } 98 99 public long getSizeInBytes() { 100 return UtilObject.getByteCount(this); 101 } 102 } 103 104 | Popular Tags |