473,395 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Cache object expiration

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.
Jan 10 '06 #1
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.

Jan 10 '06 #2
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.

Jan 10 '06 #3
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.

Jan 10 '06 #4

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.

Jan 10 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
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 =...
1
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....
4
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,...
4
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...
2
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...
1
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...
3
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...
2
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...
2
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.