views:

525

answers:

4

As title. I didn't find one via google, at any rate.

Update: thanks for the links from the two answers; this is very useful, but not what I was after - I am curious to see whether it is possible to query an IRepository backed by memcached (or some other distributed cache), backed by a RDBMS. I've really no idea how that might work in practise; I don't know very much about the internals of either distributed caches or LINQ providers.

I'm maybe envisaging something like the cache LINQ provider generating cache-keys based on the query automatically (where query could be Expression> or some kind of Specification pattern implementation), and basically can be plumped down inbetween my app and my DB. Does that sound useful?

+1  A: 

If you don't mind throwing NHibernate between them, you can use LINQ to NHibernate to query entities which can be set to use memcached as their cache.

SoloBold
Ouch! That's nasty
Orion Edwards
It depends on if you want to use NHibernate already or not ;)
SoloBold
I _do_ want to, but tragically it's not currently an option until the shortcomings of Linq2Sql are experienced "in real life".
Peter Mounce
+2  A: 

I dont if this is what you want, you can check in this website. In there you can query Memcached as well as query linq to object.

   public static IEnumerable<User> GetAllUsers()  
   {  
       // Retrieve from cache if it exists, otherwise run the query  
       return (from u in ctx.Users select u).CachedQuery("allusers");  
   }

Is this what you want ?

Here is the source code

public static IEnumerable<T> CachedQuery<T>
        (this IQueryable<T> query, string key) where T : class
{
    if (cache.KeyExists(key))
    {
        return (IEnumerable<T>)cache.Get(key);
    }
    else
    {
        IEnumerable<T> items = query.ToList();
        cache.Set(key, items);
        return items;
    }
}
Funky81
+1  A: 

Because I didn't know what memcached is I googled around and found this link:

http://latebound.blogspot.com/2008/10/using-memcached-from-c.html

Which has a section near the bottom on using LINQ queries over memcached.

Cameron MacFarland
A: 

I encounter some problem with linq for memcached also. But you should check out the serialization of your linq DBML whether it's Unidirectional or not.

you might have luck for this solution, worth to try out. For me, i sitll having problem with linq, but other object that have [Serilizable] attribute works fine.

DucDigital