-
1. Re: Active invalidation of cache entries
supinko May 17, 2010 1:30 PM (in response to supinko)Or even better, maybe the Set<VersionedKey<MyKey>> that's returned by the mythical RemoteCache.getVersionedKeySet() could have an Iterator that allowed remove():
Iterator<VersionedKey<MyKey>> iter = cache.getVersionedKeySet();
while (iter.hasNext()) {
VersionedKey<MyKey> vKey = iter.next();
MyKey key = vKey.getKey();
if (isOutdated(key)) {
iter.remove();
}
}
-
2. Re: Active invalidation of cache entries
manik May 18, 2010 8:01 AM (in response to supinko)1 of 1 people found this helpfulWhy do you need to iterate through the keys to delete them? Can't you simply attach a lifespan to each entry so it is automatically removed after that lifespan has elapsed? Or if you only want to remove the old version after a new version is added, then why not just use non-versioned keys, e.g.:
put(key, version1);
put(key, version2); // at this stage version1 will be overwritten
Cheers
Manik
-
3. Re: Active invalidation of cache entries
supinko May 18, 2010 3:18 PM (in response to manik)Hi Manik,
The nature of our data is that we have relatively few, very large data sets (some being more than a GB) that are very expensive to calculate, but once calculated, they remain valid until someone changes the inputs for the original calculation. Since the data can be valid until the end of time, I can't use either a lifespan or an idle time expiration. Unfortunately, when someone makes a change, I don't have a dependency tree to tell me exactly what has been invalidated (it's likely that only a part of the cache is invalid, so I don't want to wipe the entire cache). Also, the data is lazily calculated, so when a change happens, we don't necessarily have a new version to replace an old version with right away; the cache usually ends up with lots of stale data that never gets overwritten.
I have enough information in my keys to determine whether an entry is valid or not, so that's why I took the approach of iterating through the keys.
Thanks,
Supin
-
4. Re: Active invalidation of cache entries
manik May 24, 2010 8:00 AM (in response to supinko)1 of 1 people found this helpfulThen if your keys are small, maintain a separate list of keys in the cache? You could then retrieve this key list to iterate over and remove entries you feel are invalid.