1 16 package org.apache.cocoon.caching; 17 18 25 public final class DeltaTimeCacheValidity implements CacheValidity { 26 27 private long cachedDateTime; private long timeInCache; 30 33 public DeltaTimeCacheValidity(long minutes) { 34 this.cachedDateTime = System.currentTimeMillis(); 35 this.timeInCache = minutes * 60000; 36 } 37 38 41 public DeltaTimeCacheValidity(long minutes, long seconds) { 42 this.cachedDateTime = System.currentTimeMillis(); 43 this.timeInCache = minutes * 60000 + seconds * 1000; 44 } 45 46 49 public DeltaTimeCacheValidity(long minutes, long seconds, long milliseconds) { 50 this.cachedDateTime = System.currentTimeMillis(); 51 this.timeInCache = minutes * 60000 + seconds * 1000 + milliseconds; 52 } 53 54 public boolean isValid(CacheValidity validity) { 55 if (validity instanceof DeltaTimeCacheValidity) { 56 return Math.abs((((DeltaTimeCacheValidity)validity).getCachedDateTime() - this.cachedDateTime)) < this.timeInCache; 57 } 58 return false; 59 } 60 61 public long getCachedDateTime() { 62 return this.cachedDateTime; 63 } 64 65 public String toString() { 66 return "Delta Validity[" + this.cachedDateTime + '+' + this.timeInCache + "ms]"; 67 } 68 } 69 | Popular Tags |