if (obj.isStale())
{
if (obj instanceof RefreshableCachedObject)
{
RefreshableCachedObject rco = (RefreshableCachedObject) obj;
if (rco.isUntouched())
{
// Do not refresh an object that has exceeded TimeToLive
removeObject(id);
throw new ObjectExpiredException();
}
// Refresh Object
rco.refresh();
if (rco.isStale())
{
// Object is Expired, remove it from cache.
removeObject(id);
throw new ObjectExpiredException();
}
}
else
{
// Expired.
removeObject(id);
throw new ObjectExpiredException();
}
}
if (obj instanceof RefreshableCachedObject)
{
// notify it that it's being accessed.
RefreshableCachedObject rco = (RefreshableCachedObject) obj;
rco.touch();
}
return obj;
}