On 16 Sep 2009, at 10:03, Galder Zamarreno wrote:
Hi,
I'm looking at the TODOs in the Infinispan code base and I've seen
BdbjeCacheStore and JdbmCacheStore doing the following:
long expiry = entry.getExpiryTime();
if (entry.getMaxIdle() > 0) {
// TODO do we need both?
expiry = entry.getMaxIdle() + System.currentTimeMillis();
}
Long at = new Long(expiry);
Object key = entry.getKey();
expiryMap.put(at, key);
They use this expiry time as key in a expiryMap that they purge when
they need to expire entries from the cache store:
protected void purgeInternal() throws CacheLoaderException {
try {
Map<Long, Object> expired =
expiryMap.tailMap(System.currentTimeMillis(), true);
for (Map.Entry<Long, Object> entry : expired.entrySet()) {
expiryMap.remove(entry.getKey());
cacheMap.remove(entry.getValue());
}
} catch (RuntimeException caught) {
throw convertToCacheLoaderException("error purging expired
entries", caught);
}
}
InternalCacheEntry.getExpiryTime() says it has no meaning for entries
with max idle but without lifespan. Couldn't this be extended to
support
max idle too?
Well that would be tough since as you say it would be a moving
target. And as a moving target, it would require care in how the
value is used. E.g.,
long expiry = e.getExpiryTime();
while (expiry < System.currentTimeMillis()) {
// do some stuff
}
// remove entry
Would lead to incorrect behaviour if some other thread updates the
entry.
In the case of a cache loader this makes sense since an entry would
only be loaded if it isn't in memory (and hence no one else is using
it).
For example: TransientCacheEntry.getExpiryTime() could return
cachevalue.lastUsed + cachevalue.maxIdle. Obviously, this is not fixed
and it's really a moving target based on when it's used, but
wouldn't it
avoid code like the one above?)
In the case where both max idle and lifespan are used, i.e.
TransientMortalCacheEntry, getExpiryTime() would return whichever time
is closer to expiration. So, if lifespan says it should expiry in
Xms +
1000ms but lastUsed + maxIdle says it should expiry in Xms + 2000ms,
lifespan calculation would return, and viceversa.
Thoughts?
--
Galder Zamarreño
Sr. Software Engineer
Infinispan, JBoss Cache
_______________________________________________
infinispan-dev mailing list
infinispan-dev(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/infinispan-dev
--
Manik Surtani
manik(a)jboss.org
Lead, Infinispan
Lead, JBoss Cache
http://www.infinispan.org
http://www.jbosscache.org