Take the 2-minute tour ×

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

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?


share|improve this question
What kind of application is this for? –  Enrico Campidoglio Jun 29 '11 at 11:07
Reporting application. –  The Light Jul 13 '11 at 22:23

1 Answer 1

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).

share|improve this answer
the higher level is the view code which uses this directly, so it can't be put on a higher level; it has to be put on the same level as I don't want to introduce a new level on top of this since not needed. –  The Light Jun 29 '11 at 11:25
Well in that case, if you are using an IoC container, inject the ICacheManager in the class and fire away (or use the factory). One thing you want to think about is cache key naming as you might want to invalidate the cache when you update data. –  Mikael Östberg Jun 29 '11 at 11:44
my cache key is complex; one way, not sure it's the best way, is to define a ComplexKey class with Name and Params properties and Serialize and deserialize methods (to JSON) then using this as as my cache key. Do you know of any sample of using EL Caching in such scenario? –  The Light Jul 18 '11 at 9:47

Your Answer


