Thursday, June 02, 2005 9:52 PM
Olaf Conijn
Enterprise Library caching logic... design flaw?
A colleague of mine (somehow known as Obiwan Jacobi) pointed out what I think is a design mistake in EntLibs CacheManager API.
The flaw lies in the publicly exposed CacheManager.Contains(string) method.
Exposing this member almost ‘instructs’ a consumer of the CacheManager to write code similar to:
if (!CacheManager.Contains(cacheKey))
{
//fill cache
}
object cachedObject = CacheManager.GetData(cacheKey);
You’ve probably already noted the potential bug in the logic above, what if……. there’s a scavenger run in between the first and last line of code.
Hardly seems like a good pattern or practice, does it? ;)