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 2969
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: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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: 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,...
| |