Data is lost from my asp.net cache

A strange experience it was; losing data from the Asp.net cache.
I was refactoring some code which was used frequently in my Asp.net code, and all it did was getting a non-volatile list of items from the database. A good candidate for some caching I thought.

So I created the caching code, hit F5 and started the program.
And guess what? All new errors occurred.

While debugging I found out that the first moment I put in ten items for the cachekey, and later on I only got five out when I asked for the same data.
So what is this? A bug in the cache in .Net?
Most likely not, so I investigated the rest of the code.

And what turned out to be the case?
One function getting the data from the cache actually removed items from the list.
That is perfectly ok if the next code gets a fresh result from the database, but not if the items are removed from a list which is actually in cache.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s