Excellent question. The answer is: you can query the cache synchronously J
Here is a little experiment using PrismExplorer.
· Launch it
· Run the query “Get Customers with Orders in Oregon” query (this populates the cache with some customers and some orders)
· Put breakpoint on line in “Infrastructure.Repository” class that reads:
EntityManager.DefaultQueryStrategy = QueryStrategy.Normal;
That’s line 31 in the version on my desktop.
· Back in the UI, select “Get Orders in Cache”
· It will break here
· Open the Immediate Window
· Enter “query”; you should see something like this:
query
{value(IdeaBlade.EntityModel.EntityQueryProxy`1[DomainModel.Order])}
[IdeaBlade.EntityModel.EntityQuery<DomainModel.Order>]: {value(IdeaBlade.EntityModel.EntityQueryProxy`1[DomainModel.Order])}
CommandTimeout: 0
ElementType: {DomainModel.Order}
EntityManager: {DomainModel.DomainModelEntityManager}
QueryableType: {DomainModel.Order}
QueryStrategy: {IdeaBlade.EntityModel.QueryStrategy}
Tag: null
If you dig in, you will see that the QueryStrategy is CacheOnly
· Enter “EntityManager.ExecuteQuery(query)”; you should see something like this:
Count = 28
[0]: {DomainModel.Order}
[1]: {DomainModel.Order}
[2]: {DomainModel.Order}
[3]: {DomainModel.Order}
[4]: {DomainModel.Order}
...
[25]: {DomainModel.Order}
[26]: {DomainModel.Order}
[27]: {DomainModel.Order}
Yup. The query is executing immediately and synchronously.
I’m taking advantage of the fact that I’ve pinned this query to CacheOnly. Had I not, and it tried to satisfy the query from the database, I would have received an exception.
One common tactic is to set the EntityManager.DefaultQueryStrategy to a CacheOnly strategy. Then DevForce will attempt to satisfy all queries without an explicit strategy from the cache. You can always take a query and change its strategy by saying “q.With(QueryStrategy)” .
Just make sure the EntityManager can do what you ask of it.