Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Cache not saving

Status
Not open for further replies.

rturner003

Programmer
Nov 20, 2001
21
GB
I am developing a asp.net (2.0) application which uses data caching to save data until the user completes all the tasks. I am using the following commands:

Cache.Insert("Allocations" + strCacheNo, dtAllocations, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(60), CacheItemPriority.High, null);
Cache.Insert("Postings" + strCacheNo, dtPosting, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(60), CacheItemPriority.High, null);

dtAllocations and dtPostings are .net data tables.

On my development laptop this works fine, I can load the data, add to it and re cache it no problems.

When I loaded it on the test PC it doesn’t appear to cache at all. Any ideas on what my problem is?
 
It could be any number of things. Cache items can be removed once memory is needed so that is one possibility. I'd do some testing to check the count of the cache after each insert and and at various other intervals.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
a couple things.
1. how do you define cache. you need to use [tt]Cache c = HttpContext.Current.Cache;[/tt]. this ensures your using the same object.
2. cache is shared across all users. if your data is user specific use Session or ViewState, not cache
along these lines if the data is shared between pages use session, if it's used within one page use viewstate.
3. ususally cache is used to store relatively static data. it's also used in conjunction with data fetchers. sudo code would look like this:
Code:
public class CacheManager
{
   private Cache c = HttpContext.Current.Cache;

   public DataTable GetData()
   {
      DataTable toReturn = (DataTable)c["MyData"];
      if (toReturn == null)
      {
          toReturn = //fetch data from source
          c["MyData"] = toReturn;
      }
      return toReturn;
   }
   public void ClearData()
   {
      c.Remove("MyData"];
   }
}

//from code behind
DataTable t = new CacheManager().GetData();
or
new CacheManager().ClearData();
4. if you require session or cache rember that a user can abandon the website at anytime and create orphan data in memory. you will need to handle session/cache clean up if this is volitale data. and nothing is more of a pain than debugging orphaned session objects.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top