O/R Mapping Caching for Performance vs. Uniquing ( Identity Map Design Pattern )

Frans writes a great post about Why a cache in an O/R mapper doesn't make it fetch data faster. In fact, depending on how the cache is used, it could actually degrade performance as the management of the cache plays a factor in the performance of the O/R Mapper.

Frans mentions that the O/R Mapper's cache may not be so much about performance as it is about uniquing. Martin Fowler in Patterns of Enterprise Application Architecture refers to uniquing as the Identity Map Object-Relational Behavioral Pattern - “Ensures that each object gets loaded only once by keeping every loaded object in a map. Looks up objects using the map when referring to them.”

The idea here is that multiple requests for the same database entity in a given context refer to the same object in memory. Therefore if I ask for the same Customer multiple times in the same context, the customer will only be retrieved once from the database and placed in an identity map. Future requests for the same customer in the same context will pull the customer from the identity map ( usually a hash table ) and not from the database. In general uniquing is referred to as a good thing, but future requests for old, stale data from an identity map in a given context may not be desirable in your application.

Frans does a much better job explaining caching in O/R Mappers with another must read post.

Source: David Hayden ( Sarasota Web Design )

Filed: O/R Mappers, Design Patterns

 

posted on Tuesday, September 05, 2006 11:38 AM

Main

David Hayden Google +

David Hayden Twitter

Health & Fitness

JavaScript Patterns Book Review

HTML 5 and CSS3 - Develop with Tomorrow's Standards Today

Professional ASP.NET Design Patterns Book Review

Beginning Mac Programming Book Review

C# in Depth Book Review

ASP.NET MVC

Orchard CMS

Categories