What are some possible reasons for objects stored

2019-04-15 17:24发布

I've cached a value using the ASP.NET Cache, with the following code:

Cache.Insert("TEST_VALUE", 150, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(120));

As I understand it, this should mean that if nothing accesses that object for 120 seconds, it will expire and return null.

However, if after 10 minutes I run a page which writes out that value from the cache, it's still there (and indeed still after a whole hour). I know there's nothing else accessing it, because this is all on a local server on my machine.

Can anyone tell me why these values aren't getting purged from the cache?


Thanks, I see what you mean, but my HttpModule is checking the type of request before inserting anything into the cache, so it will only occur on form uploads.

I've tried what you suggested anyway, and the breakpoint never gets hit when I am refreshing the page that displays the cached value.

I am assuming that even reading from the cache should extend the lifespan of the object, so I am leaving it 5-10 minutes before refreshing the 'debugging' page, but the value is still there!

8条回答
再贱就再见
2楼-- · 2019-04-15 17:57

Just a debugging tip: Set the value of the cached object to DateTime.Now when you insert it in order to see when it was inserted. That way you can easily determine if it was re-inserted somehow or if something somewhere keeps accessing and thus forcing it to stay in the cache.

That combined with my suggestion about subscribing to the cache expiry event and writing to a log file should provide you with enough information to locate the problem.

查看更多
ゆ 、 Hurt°
3楼-- · 2019-04-15 17:58

Verify

<cache disableExpiration="true"/> 

is not set in your web.config?

查看更多
登录 后发表回答