Caching and DataAdapters

Posts   
 
    
brianPS
User
Posts: 3
Joined: 19-Oct-2010
# Posted on: 19-Oct-2010 22:47:11   

We have a project that was implemented in linq to sql and is being migrated to LLBLGenPro runtime using the adapter pattern.

The first version of the app did a huge amount of caching, placing entire tables into the httpcache and then doing all the linking in the codebehind. (sigh)

So you get something like :

from p in MyCacheObject.ProductPages
join cmpp in MyCacheObject.ProductContentMemberships on p.ProductPageId equals cmpp.ProductContentId
join pl in MyCacheObject.ProductPlans on cmpp.ProductLinkId equals pl.ProductPlanId 

Now, in our new repository pattern, I can build such joins with prefetch paths. You just call myRepository.GetProductPagesWithContentMemberships() and get a ProductPage entity with a collection of ProductContentMemberships.

That's great when we are talking to the db, but how do I sometimes pull from a collection of cached entities? I want to cache the tables and then use them to build my complex objects.

I can make "get from cache" vs "get from db" a decision that the repo can make, but I'm hoping I don't have to write two entirely different implementations of GetProductPagesWithContentMemberships(): one to get from db and one to use the cache.

I'm hoping there is some kind of magic adapter that I can use that will execute my linq against an object cache instead of sending it to SQL server. Is there such a thing?

This post: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=6265 hints that it is possible, but that's it.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 21-Oct-2010 21:53:12   

Hi Brian

Sorry for the delay in getting back to you - the Architecture forum does not tend to get monitored quite as closely as the other ones.

The short answer, I'm afraid, is "No"- there is no magic adapter that will do the caching for you, and LLBLGen does not support any form of caching other than using the Context object - but these are local to a user and session, and not global.

There is a good discussion about caching here including a link to an article by Frans about why we don't build it into LLBLGen.

Matt

brianPS
User
Posts: 3
Joined: 19-Oct-2010
# Posted on: 22-Oct-2010 15:49:56   

Thanks. I was hoping that there was an easy way to build a linq metadata/dataadapter that talks to my object cache instead of the db.

Any hints on how to do that?

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 26-Oct-2010 21:44:10   

Rather than trying to change the generated code to do something that it is not really designed to do, I would look to build my own caching repository layer, which uses the LLBLGen code if it needs to fetch an item from the database, and or returns an item from the cache if it is already there

Along the (very loose) lines of



public <T> GetCachedEntity<T> (int id) where T: EntityBase2,new()
{
    if (! cache.Contains<T>(id))
   { 
        var entity = new T();
        entity.Id = id;
       _adapter.FetchEntity(entity);
        cache.AddEntity(entity)
    }

    return cache.Item<T>(id);


}


Matt