tags:

views:

250

answers:

4

I have this generic list that is being cached in memory. How can I manually during testing release that object from the cache? I cleared cache on the browser but still when I refresh I get the same set of products becuase it's checking my cached object in my database retrieval method.

+2  A: 

Try Cache.Remove() method to remove an object from ASP.NET cache :

Cache.Remove("CacheKey");

Because the cached items are saved in server's memory, you can't clear application cache by clearing browser cache.

Canavar
+3  A: 

You are confusing the browser's cache (on the client machine) with server-side caching.

Babak Naffas
A: 

Your database retrieval method is running on the server, which has nothing to do with your browser cache (which is why clearing your browser cache won't do anything).

Your question isn't too clear, but I'm assuming that you're using the ASP.Net Cache object for your caching.

You'll need to add some code to your database retrieval method to refresh the item in the ASP.net cache. It would help if you could post the code that you have, but basically it would look like:

var data = DatabaseFetchStuff....
Cache["databaseInfoKey"] = data;
womp
So I have a BL method. It first checks a Generic List that we populate for the list of records. If that cached object is null, it then proceeds to call our DB layer method to retrieve the list from the DB. The problem for me is, if the cached list already is populated, it never calls my DB method. I want it to call my DB method because I changed the underlying parameterized sql behind it and I want to test the results. I could comment out the check for hte cached object and force it to call my DB method insteed to get the records but just curious on another way to do this.
CoffeeAddict
I am not using the asp.net cache object. We're jusing an object created in memory, simple as that. Again, our BL method checks that object in memory to see if it was previously populated with data. So for instance it checks a generic list instance for the data. IF null, go get the data from the database and then populate that cached object again so next time that generic list instance in memory WILL have cached data.
CoffeeAddict
You really need to post the code. If this is ASP.Net, an object in memory will not persist between page requests.
womp
again this is not an asp.net object
CoffeeAddict
>>>You really need to post the code. If this is ASP.Net, an object in memory will not persist between page requests.YES IT WILL!
CoffeeAddict
A: 

coffeeaddict you need to implement cache expiration and removal in order for your app to use updated data. If you're using your own caching implementation make sure you invalidate that cached data every time you update the persistent one, so the next time you request it it'll go up full path and cache it in-memory again.