Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Caching / August 2004

Tip: Looking for answers? Try searching our database.

Cache expiration one minute off?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
fm@newsgroups.nospam - 20 Aug 2004 22:27 GMT
Okay, what am I missing? For some reason, when I set an absolute expiration
time it is always one minute longer for which I stated. I have tried it on a
few XP machines. Obviously there is a flaw in my logic I can not see. Here is
the code that you can paste into Global.asax:

   Private Shared _nextTime As DateTime

   Private Shared Sub MyCacheCallback( _
          ByVal key As String, _
          ByVal value As Object, _
          ByVal reason As System.Web.Caching.CacheItemRemovedReason)
       Try
           Dim firstTime As DateTime = Now
           Dim lastTime As DateTime = _nextTime

           'Check the difference
           Dim diffTime As TimeSpan = Now.Subtract(lastTime)
           _nextTime = firstTime.AddMinutes(10)

           System.Web.HttpRuntime.Cache.Insert("test", 1, Nothing,
_nextTime, _
           TimeSpan.Zero, Caching.CacheItemPriority.Default, AddressOf
MyCacheCallback)

           Debug.WriteLine(lastTime.ToString("HH:mm:ss") & " off by " &
Decimal.Truncate(CDec(diffTime.TotalMinutes)) & " minutes, next up: " &
firstTime.ToString("HH:mm:ss") & " --> " & _nextTime.ToString("HH:mm:ss"))
       Catch ex As Exception
           Debug.WriteLine("Error = " & ex.Message)
       End Try
   End Sub

   Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
       ' Fires when the application is started
       'Insert something into the cache

       Dim firstTime As DateTime = Now
       _nextTime = firstTime.AddMinutes(10)

       System.Web.HttpRuntime.Cache.Insert("test", 1, Nothing, _nextTime, _
       TimeSpan.Zero, Caching.CacheItemPriority.Default, AddressOf
MyCacheCallback)

       Debug.WriteLine(firstTime.ToString("HH:mm:ss") & " --> " &
_nextTime.ToString("HH:mm:ss"))
   End Sub
Steven Cheng[MSFT] - 21 Aug 2004 06:44 GMT
Hi,

Regarding on your description and the code snippet you provided, I've also
tested it on my env and also found the same result. But the offset value is
randomly, some times less than 1miniutes ,(only several seconds). I think
this maybe the internal delay of the cache object's expiration event. Since
the cache object in the application need be monitor constantly and when a
certain item should be removed the application should fire its event and
call the event handler , that may cause the delay.  This is likely be a by
design behavior.

Regards,

Steven Cheng
Microsoft Online Support

Signature

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Signature

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

fm@newsgroups.nospam - 24 Aug 2004 21:59 GMT
Thanks for the answer Steven.

I am glad it is by design and not something funky in my code. I am okay with
the design too. It probably helps performance not to poll too often for timed
expiration. I'll make this note in our guidline documents.

> Hi,
>
[quoted text clipped - 18 lines]
> Get Preview at ASP.NET whidbey
> http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Steven Cheng[MSFT] - 25 Aug 2004 06:39 GMT
Hi ,

Thanks for your followup. I'm also very glad that my suggestions are  of
assistance. Nexttime if you have any problems, please always feel free to
post here.

Regards,

Steven Cheng
Microsoft Online Support

Signature

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Signature

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.