Ionut
Ionut

Reputation: 61

How to cache DbCompiledModel (or only its metadata) in a distributed cache

I work on a Entity Framework Code First project with a large dbContext (800+ entities).

The problem I have is that it takes up to 30 seconds to build and compile the metadata for the first time and I cannot afford having all farm servers delay the first request (WCF) in such a manner, even with the help of the AppFabric WarmUp module. An option is to cache the compiled model on a distributed cache, so other servers in the farm could take the advantage of an already existing model, when instantiating the DbContext.

Some things I found out:

Unfortunately all mentioned types are defined as internal by EF Code First (except of course DbCompiledModel) and until now I couldn't find a suitable way to cache this out of the process.

Another thing I've tried was to have a custom ObjectContext (to use it in DbContext constructor) where to programmaticaly generate/load the csdl, ssdl and msl mappings (from the db schema), but the actual views (poco classes) still remain unmapped to the overall db context.

Any help is much appreciated.

Thanks.

Upvotes: 3

Views: 2440

Answers (1)

Julie Lerman
Julie Lerman

Reputation: 4622

Try this blog post by Arthur Vickers on the EF Team: http://blog.oneunicorn.com/2012/04/21/code-first-building-blocks/

It specifically shows how to cache a compiled model.

Upvotes: 0

Related Questions