New Posts New Posts RSS Feed: Query with different order by
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Query with different order by

 Post Reply Post Reply
Author
hijaggu View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Sep-2010
Posts: 21
Post Options Post Options   Quote hijaggu Quote  Post ReplyReply Direct Link To This Post Topic: Query with different order by
    Posted: 18-Feb-2011 at 10:47am
Hi ,

I would like to understand how IdeaBlade caching works if we apply different order by criterion on same query. 

As per my understanding , once Ideablade retrieves any entities, it keeps them in cache and going forward if we query for the same entities again it uses cache instead of hitting the database again if QueryStrategy is QueryStrategy.Normal.
 
Would u plz. let me know what will be behavior of IdeaBlade if we fire below queries in given order ? 

 1.  MyEntityManager.Instance.Zips.Where<Zip> ( p => p.State.StartsWith ( "CA" ) )  --- > Load the data from database

 2.  MyEntityManager.Instance.Zips.Where<Zip>(p => p.State.StartsWith("CA")) -- > Load the data from database or use Cache ???
                                             .OrderBy(p => p.City  )
                                             .ThenBy ( p => p.Code );

3. MyEntityManager.Instance.Zips.Where<Zip> ( p => p.State.StartsWith ( "CA" ) ) -- > Load the data from database or use Cache ???
                                             .OrderBy ( p => p.Code )
                                             .ThenBy ( p => p.City );

After executing first query above , we have all zip entities for CA state in cache. What would happen if we execute
query 2 and 3 above ? Will it hit the database or sort the data already in cache and return the results ? 

- Jignesh Suthar 
  

Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 18-Feb-2011 at 1:52pm
Hi Jignesh,
 
Each query above will be executed against the data source because the EntityManager checks for the exact same query in the QueryCache. Although similar, the 3 queries are not identical.
 
Ideally, if you know the data you will work with is in cache, your explicitly set QueryStrategy to CacheOnly.
 
You can find more information on the QueryCache in our DevForce Resource Center.
 
Silvio.
Back to Top
hijaggu View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Sep-2010
Posts: 21
Post Options Post Options   Quote hijaggu Quote  Post ReplyReply Direct Link To This Post Posted: 18-Feb-2011 at 1:55pm
I am using QueryStrategy as QueryStrategy.Normal. So it should check cache first and then hit the database. is that true ?

- Jignesh
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 18-Feb-2011 at 2:57pm
Hi Jignesh,
 
To answer your question: no, it's not true.
 
Note that query cache and entity cache are not the same thing and by simply saying "cache" I'd assume you are referring to the entity cache. So maybe the answer to your question should be: it depends on what you mean by "cache" when you mentioned "it should check cache first and then hit the database".
 
To make your sentence sound correct: "it should check the query cache first and then hit the database".
 
Back to the Querystrategy: QueryStrategy.Normal has an Optimized FetchStrategy. FetchStrategy.Optimized checks the query cache to see if the current query has previously been submitted successfully. If so, it satisfies the query from the entity cache, and skip the trip to the datasource. Otherwise, a trip to the datasource is necessary.
 
You can also find more information about Query Strategies in our DevForce Resource Center.
 
Silvio.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down