Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. CacheItemRemovedCallback Problems

CacheItemRemovedCallback Problems

Scheduled Pinned Locked Moved C#
xmlhelpcsharpasp-netsysadmin
1 Posts 1 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tim Bajz
    wrote on last edited by
    #1

    Guys, I am having problems with the use of the CacheItemRemovedCallback event within an ASP.NET/C# website I am building. The below code is from my global.aspx file. The code loads XML/XSL objects into the Cache for later use. I also create a Cache dependency so should any files change which my XML/XSL objects use, the Cache is updated automatically. The code works only when something is removed from the Cache by another aspx file, since the code correctly identifies the HttpContext. However, when one of my files is changed and the RemovedCallback() function is fired, for some reason the Context and the HttpContext are both null. As such my code never has a chance to update the Cache again. Rather it exists "without an error" as soon as I try to use Cache.Insert. Does anyone know if this is a bug in Beta 2, or am I missing something, like the use of a special Context object? Any help greatly appreciated.......... Cheers, Tim. <%@ Import Namespace="System.Xml.Xsl" %> <%@ Import Namespace="System.Xml.XPath" %> <%@ Import Namespace="System.Web.Caching" %> <%@ Import Namespace="CommerceEngine.Common" %> private static CacheItemRemovedCallback onRemove = null; private XPathDocument CommerceListXmlObj; private XslTransform CommerceListXslObj; public void Application_OnStart() { ApplicationConfiguration.OnApplicationStart(Context.Server.MapPath( Context.Request.ApplicationPath )); onRemove = new CacheItemRemovedCallback(this.RemovedCallback); CommerceListXmlObj = new XPathDocument(CommerceEngineConfiguration.CommerceListXmlFilePath); HttpContext.Current.Cache.Insert("CommerceListXmlObj", CommerceListXmlObj, new CacheDependency (CommerceEngineConfiguration.CommerceListXmlFilePath), DateTime.Now.AddHours(1), TimeSpan.Zero, CacheItemPriority.Default, CacheItemPriorityDecay.Slow, onRemove ); CommerceListXslObj = new XslTransform(); CommerceListXslObj.Load(CommerceEngineConfiguration.CommerceListXslFilePath); HttpContext.Current.Cache.Insert("CommerceListXslObj", CommerceListXslObj, new CacheDependency(CommerceEngineConfiguration.CommerceListXslFilePath), DateTime.Now.AddHours(1), TimeSpan.Zero, CacheItemPriority.Default, CacheItemPriorityDecay.Slow, onRemove ); } public void RemovedCallback(String k, Object v, CacheItemRemovedReason r) { switch(k) { case "CommerceListXmlObj" : CommerceListXmlObj = new </x-turndown>

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups