Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用缓存应用程序块在Asp.net应用程序的存储库层进行缓存_C#_.net_Asp.net_Caching_Enterprise Library - Fatal编程技术网

C# 使用缓存应用程序块在Asp.net应用程序的存储库层进行缓存

C# 使用缓存应用程序块在Asp.net应用程序的存储库层进行缓存,c#,.net,asp.net,caching,enterprise-library,C#,.net,Asp.net,Caching,Enterprise Library,在我的一个Web应用程序中,我试图缓存一些引用实体,以减少数据库命中率。我使用缓存应用程序块来实现缓存。我对它还不熟悉,我不确定它的实施情况。我已经编写了一个示例存储库来利用它。 我希望你们大家都能看一看并发表评论 public class StatusRepository { ICacheManager statusCahce = CacheFactory.GetCacheManager(); //I am not sure whether I should initi

在我的一个Web应用程序中,我试图缓存一些引用实体,以减少数据库命中率。我使用缓存应用程序块来实现缓存。我对它还不熟悉,我不确定它的实施情况。我已经编写了一个示例存储库来利用它。 我希望你们大家都能看一看并发表评论

public class StatusRepository
    {
        ICacheManager statusCahce = CacheFactory.GetCacheManager(); //I am not sure whether I should initilise statusCache object here.

     public StatusEntity Get(byte statusId)
        {
            StatusCollection statusCollection = (StatusCollection)statusCahce.GetData("Statuses");
            if (statusCollection != null)
            {
                return (StatusEntity)statusCollection.StatusList.First(p=>p.StatusId==statusId);
            }
            else
            {
               // HIT Database to get the entity
            }
        }
       public StatusCollection GetStatusList()
        {
            StatusCollection statusCollection = (StatusCollection)statusCahce.GetData("Statuses");
            SqlHelper sql = new SqlHelper(true);
            if (statusCollection != null) //We have it in cache
            {
                return statusCollection;
            }
            else //Hit Database
            {

                     //Hit Database to get the StatusCollection and add that           collection to cache       

                    statusCahce.Add("Statuses", statusCollection);
                    return statusCollection;
                }
            }
        }
    }
}
请让我知道,我如何才能改进它


还请让我知道,缓存中可以有多少数据。

类似的东西可能有用?

根据MSDN,CacheFactory已不再使用。你为什么不描述一下你真正想要实现的目标,这样人们就可以提出替代技术或方法。