tags:

views:

141

answers:

2

Hello,

been pulling my hair out over this for the past few hours.

i have a cache object..

HttpRuntime.Cache.Insert("Members", AllMembersList, null, DateTime.Now.AddHours(1), TimeSpan.Zero);

when i try and clear the cache object..

HttpRuntime.Cache.Remove("Members");

its value doesnt change, untill 1 hour is up or when i reset the server.

My question.. for a cache object that is set absolute expiration, can i manually clear it or will it exist for the full hour ?

what i would like is this object to last for an hour but depending on program execution be able to clear it so it will contain fresh data.

any help is most appreciated

truegilly

+1  A: 

The Remove method should work fine for this.

Are you sure that you're calling Remove correctly and that there isn't some other code re-inserting the item into the cache?

LukeH
thanks for the responses,im still having problems with this. could it be that..1 - im trying to clear the cache from a subdomain of my site admin.mysite.co.uk and 2 im using a LINQ data context rather than a direct database query ?
Truegilly
+1  A: 

From http://www.neovolve.com/page/Cache-Expiration-Policies.aspx

When are items actually flushed from the cache?

Most caching frameworks will only remove expired items from the cache when system resources are scarce or when the cache is referenced. This means that a cache entry that has expired due to an absolute or sliding expiration may not be removed from the cache until some future time which may be well after the entry actually expired.

This is done for performance. The caching frameworks normally use a scavenging algorithm that looks for expired entries and removes them. This is typically invoked when the cache is referenced rather than when the items actually expire. This allows the cache framework to avoid having to constantly track time based events to know when to remove items from the cache.

You could try setting the cached value to null.

GalacticCowboy