@@ -122,7 +122,7 @@ class Cache<K, V> implements LogSupport, AdminStats {
122122 /* * @returns the cached Entry at key. */
123123 CacheEntry<V> getEntry (K key ) {
124124 def ret = _map[key]
125- if (ret && shouldExpire(ret)) {
125+ if (ret != null && shouldExpire(ret)) {
126126 remove(key)
127127 return null
128128 }
@@ -132,7 +132,7 @@ class Cache<K, V> implements LogSupport, AdminStats {
132132 /* * @returns cached value for key, or lazily creates if needed. */
133133 V getOrCreate (K key , Closure<V> c ) {
134134 CacheEntry<V> entry = _map[key]
135- if (! entry || shouldExpire(entry)) {
135+ if (entry == null || shouldExpire(entry)) {
136136 def val = c(key)
137137 put(key, val)
138138 return val
@@ -166,7 +166,8 @@ class Cache<K, V> implements LogSupport, AdminStats {
166166
167167 /* * @returns the timestamp of the cached Entry at key. */
168168 Long getTimestamp (K key ) {
169- return getEntryTimestamp(_map[key])
169+ def entry = _map[key]
170+ return entry != null ? getEntryTimestamp(entry) : null
170171 }
171172
172173 /**
@@ -263,20 +264,18 @@ class Cache<K, V> implements LogSupport, AdminStats {
263264 }
264265
265266 private boolean shouldExpire (CacheEntry<V> entry ) {
266- if (expireFn) return expireFn. call(entry)
267+ if (expireFn != null ) return expireFn. call(entry)
267268
268- if (expireTime) {
269+ if (expireTime != null ) {
269270 Long timestamp = getEntryTimestamp(entry),
270271 expire = (expireTime instanceof Closure ? expireTime. call() : expireTime) as Long
271- return intervalElapsed(expire, timestamp)
272+ return currentTimeMillis() > timestamp + expire
272273 }
273274 return false
274275 }
275276
276277 private Long getEntryTimestamp (CacheEntry<V> entry ) {
277- if (! entry) return null
278- if (timestampFn) return asEpochMilli(timestampFn. call(entry. value))
279- return entry. dateEntered
278+ return timestampFn != null ? asEpochMilli(timestampFn. call(entry. value)) : entry. dateEntered
280279 }
281280
282281 private void fireOnChange (Object key , V oldValue , V value ) {
0 commit comments