What's the best practice for caching data within a request?
More specifically, let's say I a have a table with several rows of data and each row needs to do a separate database query to get details on a Bakery. I know that by the end of the request I will have to get data on each individual Bakery in Boston. I'd like to select all Bakeries I need in one shot before I add data to the table so I have them.
1) If I do BakeriesTableRetrieval.GetRows( new BakeriesTableEqualityCondition.CityId( CityIds.Boston ) ), will database caching magically not have to make a round trip when I later do BakeriesTableRetrieval.GetRowMatchingId( idOfSomeBakeryInBoston )?
2) Assuming 1 is false or that I have a different situation where I just need to cache my own stuff, how do I best keep my own pre-request cache?
My answers below apply when you are using EWL's own web framework (EWF), or if you are otherwise inside a
DataAccessState.Current.ExecuteWithCache
block.Yes, database caching will automatically eliminate those single-row queries, as long as you are using Table Retrieval. With Query Retrieval, you can accomplish the same thing if you implement the
updateSingleRowCaches
partial method.Use
DataAccessState.Current.GetCacheValue
.