开发者

losing my objects at cache

I am using IIS7 and c# and mysql. and I put some objects into asp.net cache system with sql keywords. it has very simple logic.put the selected dataset into cache with the given sql keyword.

here is the problem. when I call my site with www.abc.com it works normal. while surfing in abc.com after second click firstly filled dataset becomes empty datasets and my site start showing empty lists.

I tried changing keys to some static words and copy datasets then cache them but no success so far.

I hope I explained well. http://beta.mpazari.com is the place if you like to see and at red boxes dropdowns is the li开发者_如何转开发sts should have been filled with data.

here is the my fill function

public void Fill(ref DataSet ds, string sql, DateTime? cacheTime, string key)
    {
        if (key == null) key = sql;
        if (cacheTime == null) cacheTime = DateTime.Now.AddMinutes(generalCacheExpiarionTimeInMinutes);
        if (cache[key] != null) { ds = (DataSet)cache[key]; return; }
        MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["motorConnectionString"].ConnectionString);
        try
        {
            conn.Open();
            MySqlDataAdapter myda = new MySqlDataAdapter(sql, conn);
            if (ds == null) ds = new DataSet();

            ds.Clear();
            myda.Fill(ds);
            cache.Insert(key, ds.Copy(), null, cacheTime.Value, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.NotRemovable,null);
        }
        finally
        {
            conn.Close();
        }
    }

thanks in advance.


Which Cache are you using? ASP.NET has several places that you can cache...I would suspect that you might be putting this in the cache that is disposed of at the end of each request.

See these...
http://msdn.microsoft.com/en-us/library/system.web.httpcontext.cache.aspx
(Context Cache...persists for the life of the app domain)

http://msdn.microsoft.com/en-us/library/system.web.httpcontext.items.aspx
(Request Cache...persists until the end of the Request)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜