Hello All,
I inserted an object into cache with absolute expiration using the following
code:
DateTime AbsoluteExpirationDate = DateRangesForDataLists[0,0].AddDays(1);
//Expires the next day
Cache.Insert("DataListStartEndDates",DateRangesFor DataLists,null,AbsoluteExpirationDate,TimeSpan.Zer o);
How can I know if the above cache object expired or not before accessing? Is
there any API in cache class that I could use?
Any pointers?
Thank you. 4 2968
the simplest way to test for expiration is to check if the Cache item is null:
if Cache["DataListStartEndDates"]==null)
{
// re-add the item here
}
You can also configure CacheItemRemoved calllback that gets fired when the
item is evicted from the Cache. the documentation at MSDN or in your local
help shows example code.
Peter
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
"Diffident" wrote: Hello All,
I inserted an object into cache with absolute expiration using the following code:
DateTime AbsoluteExpirationDate = DateRangesForDataLists[0,0].AddDays(1);
//Expires the next day Cache.Insert("DataListStartEndDates",DateRangesFor DataLists,null,AbsoluteExpirationDate,TimeSpan.Zer o);
How can I know if the above cache object expired or not before accessing? Is there any API in cache class that I could use?
Any pointers?
Thank you.
So if the cache object's expiration has expired it is instantly set to null?
Thank you.
"Peter Bromberg [C# MVP]" wrote: the simplest way to test for expiration is to check if the Cache item is null:
if Cache["DataListStartEndDates"]==null) { // re-add the item here }
You can also configure CacheItemRemoved calllback that gets fired when the item is evicted from the Cache. the documentation at MSDN or in your local help shows example code. Peter
-- Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com UnBlog: http://petesbloggerama.blogspot.com
"Diffident" wrote:
Hello All,
I inserted an object into cache with absolute expiration using the following code:
DateTime AbsoluteExpirationDate = DateRangesForDataLists[0,0].AddDays(1);
//Expires the next day Cache.Insert("DataListStartEndDates",DateRangesFor DataLists,null,AbsoluteExpirationDate,TimeSpan.Zer o);
How can I know if the above cache object expired or not before accessing? Is there any API in cache class that I could use?
Any pointers?
Thank you.
Diffident,
When an object in Cache expires, it is "evicted" - it's no longer there. So
if you look for it by key, you will get null.
Actually testing for null before attempting to access anything in Cache ,
Session, Application or Viewstate is a good programming practice.
Hope that helps.
Peter
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
"Diffident" wrote: So if the cache object's expiration has expired it is instantly set to null?
Thank you.
"Peter Bromberg [C# MVP]" wrote:
the simplest way to test for expiration is to check if the Cache item is null:
if Cache["DataListStartEndDates"]==null) { // re-add the item here }
You can also configure CacheItemRemoved calllback that gets fired when the item is evicted from the Cache. the documentation at MSDN or in your local help shows example code. Peter
-- Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com UnBlog: http://petesbloggerama.blogspot.com
"Diffident" wrote:
Hello All,
I inserted an object into cache with absolute expiration using the following code:
DateTime AbsoluteExpirationDate = DateRangesForDataLists[0,0].AddDays(1);
//Expires the next day Cache.Insert("DataListStartEndDates",DateRangesFor DataLists,null,AbsoluteExpirationDate,TimeSpan.Zer o);
How can I know if the above cache object expired or not before accessing? Is there any API in cache class that I could use?
Any pointers?
Thank you.
Thank you!! That helped.
"Peter Bromberg [C# MVP]" wrote: Diffident, When an object in Cache expires, it is "evicted" - it's no longer there. So if you look for it by key, you will get null. Actually testing for null before attempting to access anything in Cache , Session, Application or Viewstate is a good programming practice. Hope that helps. Peter -- Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com UnBlog: http://petesbloggerama.blogspot.com
"Diffident" wrote:
So if the cache object's expiration has expired it is instantly set to null?
Thank you.
"Peter Bromberg [C# MVP]" wrote:
the simplest way to test for expiration is to check if the Cache item is null:
if Cache["DataListStartEndDates"]==null) { // re-add the item here }
You can also configure CacheItemRemoved calllback that gets fired when the item is evicted from the Cache. the documentation at MSDN or in your local help shows example code. Peter
-- Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com UnBlog: http://petesbloggerama.blogspot.com
"Diffident" wrote:
> Hello All, > > I inserted an object into cache with absolute expiration using the following > code: > > DateTime AbsoluteExpirationDate = DateRangesForDataLists[0,0].AddDays(1); > > //Expires the next day > Cache.Insert("DataListStartEndDates",DateRangesFor DataLists,null,AbsoluteExpirationDate,TimeSpan.Zer o); > > How can I know if the above cache object expired or not before accessing? Is > there any API in cache class that I could use? > > Any pointers? > > Thank you. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Florian Lindner |
last post by:
Hello,
I am building a object cache in python, The cache has a maximum size and the
items have expiration dates.
At the moment I'm doing like that:
cache = {} # create dictionary
cache =...
|
by: Joe Fallon |
last post by:
I am trying to setup a cache that refreshes itself every hour. (My sample
code is for every minute so I can test it.)
I have found some examples that I thought worked but they all seem to fail....
|
by: NWx |
last post by:
Hi,
I' trying to implement a callback method when a cache object expires
I want to do this to automatically logout user after a timeout (for demo
purposes)
My thought is, when user logon,...
|
by: Mat |
last post by:
Hi,
I've stumbled onto a problem when using the caching object in ASP.Net.
I'm placing a static dataset to the cache as the data only changes
once a day. Whilst writing to the cache I'm using...
|
by: Dicky Cheng |
last post by:
Hi,
I am using absolute expiration to expire my cache object in Cache API. And I
set it to expire after 60min. Then I test it, it cache, and everything fine.
Then I stop working and lock...
|
by: Guadala Harry |
last post by:
AFAIK, when placing an object into the Cache with no special instructions
(no dependencies, sliding expirations, hard expirations, etc), it will just
sit there in the Cache until the system decides...
|
by: MattC |
last post by:
Hi,
I am persisting the viewstate for each page into the Cache object, below is
shown my methods for saving and loading:
I am able to save the viewstate to the cache and most times I can load...
|
by: Kikoz |
last post by:
Hi all.
I keep my ViewState in server's cache. Works fine except when user leaves
the page opened for a long time (2 hours or so). Then if he/she tries to
post it back the server throws an...
|
by: sternr |
last post by:
Hey,
(Sorry if the thread has been posted twice!)
I'm using the System.Web.Caching.Cache object in my Win App and
basically, it's great!
I use a sliding expiration TimeStamp to the object I put...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |