1 package org.apache.turbine.services.cache; 2 3 18 19 35 public class RefreshableCachedObject 36 extends CachedObject 37 { 38 39 43 private long timeToLive = -1; 44 45 48 private long lastAccess; 49 50 56 public RefreshableCachedObject(Refreshable o) 57 { 58 super(o); 59 lastAccess = System.currentTimeMillis(); 60 } 61 62 69 public RefreshableCachedObject(Refreshable o, 70 long expires) 71 { 72 super(o, expires); 73 lastAccess = System.currentTimeMillis(); 74 } 75 76 81 public synchronized void setTTL(long timeToLive) 82 { 83 this.timeToLive = timeToLive; 84 } 85 86 91 public synchronized long getTTL() 92 { 93 return timeToLive; 94 } 95 96 99 public synchronized void touch() 100 { 101 lastAccess = System.currentTimeMillis(); 102 } 103 104 108 public synchronized boolean isUntouched() 109 { 110 if (timeToLive < 0) 111 return false; 112 113 if (lastAccess + timeToLive < System.currentTimeMillis()) 114 return true; 115 else 116 return false; 117 } 118 119 122 public void refresh() 123 { 124 Refreshable r = (Refreshable) getContents(); 125 synchronized (this) 126 { 127 created = System.currentTimeMillis(); 128 r.refresh(); 129 } 130 } 131 } 132 | Popular Tags |