views:

75

answers:

2

Hi,

Is there any way to cache LINQ to SQL queries by looking at the parameters that were previously passed and bypass the database all together?

I know L2S caches some database calls, but I'm looking for a permanant solution as in, even if the applciation restarts, that cache reloads and never asks the database again.

Are there any frameworks for C#?

+1  A: 

Linq-to-SQL wasn't really designed for this, the context is actually intended to have a short lifespan, not a long one. If you want to cache some specific queries, I'd recommend using a different medium, not actually relying on the context itself.

Here's one option to get an idea of what I mean: Caching the results of LINQ queries

Alternatively if there are a few things you just access non-stop that rarely change, consider just caching a List<T> or some other form of the result and forcing a re-cache when needed.

Nick Craver
A: 

When you say that you'd like the results to cache across applications restarts, it sounds like you have a occasionally connected application that you'd like to keep a cache of results in case you lose network connection. If this is indeed the case, have a look at the Sync Framework, which does exactly that. It also allows you to change the cached data, and when the client regains connection, transmit the data and resolve any conflicts. Since it persists the cache to disk (usually by using SQL Server Compact), it will survive application restarts (or even computer restarts).

Allon Guralnek