开发者

How to Cache LINQ to SQL Results?

开发者 https://www.devze.com 2023-03-16 07:58 出处:网络
I\'m using LINQ to SQL to call some reporting stored procedures. Each stored procedure returns a class which accepts some input parameters, for example:

I'm using LINQ to SQL to call some reporting stored procedures.

Each stored procedure returns a class which accepts some input parameters, for example:

public partial class csp_WeekCommencingListResult
{        
    public static IEnumerable<csp_WeekCommencingListResult> GetAll(int? masterTrackingGroupId)
    {
        using (var dataContext = OscaDataContext.CreateWithCustomTimeOut())
        {
            return dataContext
                .csp_WeekCommencingList(masterTrackingGroupId)
              开发者_如何转开发  .ToList();
        }
    }
}

How could I cache the result of the stored procedure for the passed parameters?

For example, when 1 is passed to this stored procedure, its result should be cached for a day.

Any thoughts? is there any framework I can use? or I have to build my own custom cache manager per stored procedure using the .NET Cache object?

Thanks,


You should probably add caching at a higher level, for example in the code that is calling this code.

Try to figure out a good caching strategy that works with your project.

And when it comes to cache managers, I usually use the ICacheManager from Microsoft EnterpriseLibrary Caching which I property inject with some dependency injection framework like Castle or StructureMap. That way I can run different configurations for different environments (dev, test, prod etc).

0

精彩评论

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