Cache with Callback problems... threading?

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Cache with Callback problems... threading?

    I'm having a problem using the Cache object with asp.net. Here is what I
    have:
    1) I put something in cache and set its callback method.
    2) The object times out after X minutes and calls the callback method
    specified.
    3) The callback method gets the newest version of the item from the db and
    then calls a helper method to put the item back into cache. It looks like
    this:

    //Pseudocode
    // Called once by app
    Initialize()
    {
    Data myData = DataTier.GetData();
    AddDataToCache("key", myData);
    }

    // Puts item into cache with 10 minute expiration AddDataToCache(string key,
    object data) {
    // Delegate for expiring callback
    CacheItemRemovedCallback onRemove;
    onRemove = new CacheItemRemovedCallback(RemovedCallback);
    // Add data to the cache
    HttpContext.Current.Cache.Add(key, data, null, DateTime.Now.AddMinutes(10),
    TimeSpan.Zero, CacheItemPriority.High, onRemove);
    }

    // Called when item expires
    RemovedCallback(string key, object value, CacheItemRemovedReason reason)
    {
    Data myData = DataTier.GetData();
    AddDataToCache(key, myData);
    // Any code here won't be called!
    }



    That's basically the scenario. Ideally, I would initialize the system once,
    and then it would automatically refresh the data within it every time the
    cache expired.
    When debugging though, after the cache times out, the item is not put back
    in. It is very strange. RemovedCallback is called, but if I put a trace
    statement after the AddDataToCache method call, the trace is never written.
    Does anyone have an idea as to what is happening?
    Thanks,
    Brian


    Brian Vallelunga Guest

  2. Similar Questions and Discussions

    1. Problems with Trust Cache
      :confused; We are having a problem with response time to our webservers running CF ver. 5 . This started after a template change was made by our...
    2. Problems with cache - PHP returns always the same XML
      Hello, I've develope an aplication in Flash MX 2004, using PHP&XML to comunicate the aplication with the DDBB. Then, If I load an XML object in...
    3. Cache DataGrid Datasource, Add/Delete rows and rebind problems
      Hi all, Is there any way to cache the Datasource of datagrid and allow to add/delete row in cache, then rebind the datagrid from cached...
    4. Safari Cache problems with Flash in DWMX?
      I have a flash site created in DWMX. A button on the page in flash pops up a new window, containing flash navigation to choose between different...
    5. PB1400C/NUpowr G3 1400 cache problems
      Hi folks, Some time ago the control panel for this hardware started to refuse to take any backside cache speed setting, stating that too high a...
  3. #2

    Default Re: Cache with Callback problems... threading?

    Hi,

    Here is the problem ... you are using the current context to get the
    application and set the cache. This works perfectly when the application
    init. But when the cache remove callback called there isn’t any request
    and the current context not existing. To overcome this issue add private
    variable to the global class that will hold the application then set him
    when the application start. Now you can use the application variable.

    you can see my example (and download) from :
    [url]http://www.developersdex.com/gurus/code/653.asp[/url]

    Natty Gur, CTO
    Dao2Com Ltd.
    28th Baruch Hirsch st. Bnei-Brak
    Israel , 51114

    Phone Numbers:
    Office: +972-(0)3-5786668
    Fax: +972-(0)3-5703475
    Mobile: +972-(0)58-888377

    Know the overall picture


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur Guest

  4. #3

    Default Re: Cache with Callback problems... threading?

    Hmm... thanks for the help. Unfortunately, I don't think the method
    described below will help me. The page I am using this on actually caches
    many different things, and I don't know what all of them will be at the
    start of the application. Do you have an idea of how I could still go about
    doing this?

    Brian


    "Natty Gur" <natty@dao2com.com> wrote in message
    news:%23tFfYcaUDHA.360@TK2MSFTNGP11.phx.gbl...
    > Hi,
    >
    > Here is the problem ... you are using the current context to get the
    > application and set the cache. This works perfectly when the application
    > init. But when the cache remove callback called there isn't any request
    > and the current context not existing. To overcome this issue add private
    > variable to the global class that will hold the application then set him
    > when the application start. Now you can use the application variable.
    >
    > you can see my example (and download) from :
    > [url]http://www.developersdex.com/gurus/code/653.asp[/url]
    >
    > Natty Gur, CTO
    > Dao2Com Ltd.
    > 28th Baruch Hirsch st. Bnei-Brak
    > Israel , 51114
    >
    > Phone Numbers:
    > Office: +972-(0)3-5786668
    > Fax: +972-(0)3-5703475
    > Mobile: +972-(0)58-888377
    >
    > Know the overall picture
    >
    >
    > *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    Brian Vallelunga Guest

  5. #4

    Default Re: Cache with Callback problems... threading?

    I think you miss understand me. What I suggested is to save the
    application in a class level variable inside the global class so you can
    use it when the cache period will be finish and you want to refill the
    cache.

    Natty Gur, CTO
    Dao2Com Ltd.
    28th Baruch Hirsch st. Bnei-Brak
    Israel , 51114

    Phone Numbers:
    Office: +972-(0)3-5786668
    Fax: +972-(0)3-5703475
    Mobile: +972-(0)58-888377

    Know the overall picture


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139