简体   繁体   中英

How do I cache something within a request in EWL?

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.

  1. 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.

  2. Use DataAccessState.Current.GetCacheValue .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM