Lazycoder

30Jan/060

When a cache isn’t a cache

K. Scott Allen : Wierd Caching: “but don’t forget the cache itself can ‘automatically remove seldom used or unimportant items’.”

So I’m peacefully reading through my RSS feeds and I read this post by K. Scott Allen. I don’t see the bug at first, I’m thinking it has something to do with threading and ask about using a lock on the item being retrieved from the cache. Scott replies with the above statement. I thought, “That’s odd. It’s not really a cache then. It’s more like a slot machine.”

I’ve always taken for granted that items I place in the cache will be there when I come back, unless the cache is invalidated or some code in another thread comes in and removes it.

(sigh) Once again, I’ve lost my innocence.

I’m sure that the cache doesn’t remove items without good reason, like maybe all of the references to the item are gone. But it still gives me a little pause.

Filed under: .NET Leave a comment