enormego/EGOCache — Issue #10: Old key entries are never removed from cache dictionary plist
Author: jpm
Created: 2012-02-15 04:16:47+00:00
State: open

So I'm debugging memory usage in one of my client's apps, and I ended up reviewing how EGOCache is keeping track of its objects. In the init method there's this interesting little bit of code:

for(NSString* key in cacheDictionary) {
NSDate* date = [cacheDictionary objectForKey:key];
if([[[NSDate date] earlierDate:date] isEqualToDate:date]) {
[[NSFileManager defaultManager] removeItemAtPath:cachePathForKey(key) error:NULL];
}
}

It's interesting to me because the code seems to be checking the entries in the EGOCache.plist file, and seeing if there are entries there that have the date object being older than "right now". If so, remove the cache file from disk.

Seems perfect, however the cache dictionary entry itself is still kept, so the EGOCache.plist file keeps growing and growing. I have a file that has been around for a while, with close to 10,000 entries in the plist file. Most of the entries have dates in 2011.

Is there a reason for not deleting these cache dictionary entries? I'm assuming it's just something being overlooked, but wanted to check before modifying the code to fix this.

--Joao