Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'll start by addressing the follow up question:</p> <blockquote> <p>... is that sometimes Cache returns null ...</p> </blockquote> <p>This can be because presumably it takes some time for the background thread to fill the cache. When <code>Application_Start</code> fires, you start up the background thread and then the <code>Application_Start</code> finishes. The application can then move on to other tasks, for instance processing a page.</p> <p>If during the processing of the page, an attempt is made to access the cache before the initial run of <code>AddDataInCache</code> has finished, then the cache will return null.</p> <p>Regarding memory consumption, I don't immediately see how you could improve the situation unless you are able to reduce the amount of row in the cached DataTables.</p> <p>In the first call to <code>AddDataInCache</code>, the cache is empty to begin with. Then your GetAllDataForCaching creates two DataTables and fill them with data. This causes the process to aquire memory to store the data in the DataTables.</p> <p>On the second and subsequent calls to <code>AddDataInCache</code>, the cache already holds all the data that was fetched on the previous run. And then again you create two new datatables and fill them with data. This causes the memory consuption to go up again in order to hold both the preexisting data in cache and the new data in the DataTables created in the second run. Then once the second run has completed loading the data you overwite the preexisting data in the cache with the new data fetched in the second run.</p> <p>At his point the data that was in the cache from the first run becomes eligible for <a href="http://msdn.microsoft.com/en-us/library/0xy59wtx.aspx" rel="nofollow">garbage collection</a>. But that doesn't mean that the memory will be immediately reclaimed. The memory will be reclaimed when the garbage collector comes around and notices that the DataTables are no longer needed in memory.</p> <p>Note that the cached items from the first run will only become eligible for garbage collection if no "live" objects are holding a reference to them. Make sure that you keep your cache usage short lived.</p> <p>And while all of this is going on, your background thread will happily go about its business refreshing the cache. It's therefore possible that a third cache refresh occurs before the garbage collector releases the memory for the DataTables fetched in the first run, causing the memory consumption to increase further.</p> <p>So in order to decrease the memory consumption, I think you will simply have to reduce the amount of data that you store in the cache (fewer rows, fewer columns). Increasing the time between cache refreshes might also be helpful. </p> <p>And finally, make sure you are not keeping old versions of the cached objects alive by referencing them in long lived requests/application processes.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload