1 17 package org.alfresco.repo.cache; 18 19 26 public class ExpiringValueCache<T> 27 { 28 private final static long TIMEOUT_DEFAULT = 1000L*60L; 30 31 private long timeout = TIMEOUT_DEFAULT; 32 private long snapshot = 0; 33 private T value; 34 35 40 public ExpiringValueCache() 41 { 42 } 43 44 49 public ExpiringValueCache(long timeout) 50 { 51 this.timeout = timeout; 52 } 53 54 60 public void put(T value) 61 { 62 this.value = value; 63 this.snapshot = System.currentTimeMillis(); 64 } 65 66 71 public T get() 72 { 73 if (snapshot + timeout < System.currentTimeMillis()) 74 { 75 this.value = null; 76 } 77 return this.value; 78 } 79 80 83 public void clear() 84 { 85 this.value = null; 86 } 87 } 88 | Popular Tags |