Hello All,
I inserted an object into cache with absolute expiration using the following
code:
DateTime AbsoluteExpirat ionDate = DateRangesForDa taLists[0,0].AddDays(1);
//Expires the next day
Cache.Insert("D ataListStartEnd Dates",DateRang esForDataLists, null,AbsoluteEx pirationDate,Ti meSpan.Zero);
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 2991
the simplest way to test for expiration is to check if the Cache item is null:
if Cache["DataListStartE ndDates"]==null)
{
// re-add the item here
}
You can also configure CacheItemRemove d 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 AbsoluteExpirat ionDate = DateRangesForDa taLists[0,0].AddDays(1);
//Expires the next day Cache.Insert("D ataListStartEnd Dates",DateRang esForDataLists, null,AbsoluteEx pirationDate,Ti meSpan.Zero);
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["DataListStartE ndDates"]==null) { // re-add the item here }
You can also configure CacheItemRemove d 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 AbsoluteExpirat ionDate = DateRangesForDa taLists[0,0].AddDays(1);
//Expires the next day Cache.Insert("D ataListStartEnd Dates",DateRang esForDataLists, null,AbsoluteEx pirationDate,Ti meSpan.Zero);
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["DataListStartE ndDates"]==null) { // re-add the item here }
You can also configure CacheItemRemove d 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 AbsoluteExpirat ionDate = DateRangesForDa taLists[0,0].AddDays(1);
//Expires the next day Cache.Insert("D ataListStartEnd Dates",DateRang esForDataLists, null,AbsoluteEx pirationDate,Ti meSpan.Zero);
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["DataListStartE ndDates"]==null) { // re-add the item here }
You can also configure CacheItemRemove d 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 AbsoluteExpirat ionDate = DateRangesForDa taLists[0,0].AddDays(1); > > //Expires the next day > Cache.Insert("D ataListStartEnd Dates",DateRang esForDataLists, null,AbsoluteEx pirationDate,Ti meSpan.Zero); > > 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 = (object, timestamp) # Save a tuple with the object itself and a
timestamp (from datetime.datetime.now()) under a unique object ID. This
make looking up a certain item a cheap operation (AFAIK). After looking up
|
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.
(They only work when I click the submit button - not when the cache
expires.)
In my Login form I have:
Global.AddItemToCache("CacheTime", Date.Now, 60)
|
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, create a cache object which expires after,
let's say, 15 minutes, and in that moment, to direct user to a page telling
the time to run demo app was expired.
|
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 a lock using code
like below (just typed this in);
Cache thisCache = HttpContext.Current.Cache
lock(thisCache)
|
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 computer (pc still running), then leave office.
Second day I come to the office and unlock computer, the cache still doesn't
expire! (It already exceed 60min). And I use the cache, and it still
working. And after awhile, the cache start flushing. So I am...
| |
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 it needs to remove the
object to free up memory. (If my understanding so far is wrong, please
clarify)
What I'd like to know is that if I place an object into the Cache with a
sliding expiration - is it possible/likely that the system will...
|
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 it
ok, however it seems that every now and again it fails to Deserialize the
viewstate.
My Application pool is set to shutdown after 180mins of idle.
|
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 exception saying that ViewState was
invalid. I suspect it has something to do with cache expiration time. Can I
control its expiration time from within my web.config? Or anyhow? Couldn't
find anything related in web or machine config files or...
|
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 in the Cache.
When I try and get the object after it's sliding expiration time I get
null (as excepted of course),
But the problem is that the memory is never cleaned - my application's
memory just keeps on growing event after the object...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |