Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: Re: [eclipselink-users] Caching read-all queries

For those interested, I've written a blog entry on how I integrated
this with EhCache:

http://weblogs.java.net/blog/zarar/archive/2010/05/31/integrating-eclipsellink-ehcache-cache-readall-and-native-queries



On Tue, Jun 1, 2010 at 9:29 AM, James Sutherland <jamesssss@xxxxxxxxx> wrote:
>
> No, you will only see SQL if the SQL is sent to the database.
>
> By default any Query will access the database, where as any find()
> operation, or ToOne relationship access will first check the object cache.
>
> On any primary key (Id) Query, you can configure it using the
> "eclipselink.cache-usage" query hint to "CheckCacheByPrimaryKey".  If the
> Query returns a single object, you can use "CheckCacheThenDatabase" (you
> can't use this for a result list as EclipseLink can not know if it has them
> all in the cache).  If you know you have all the objects in the cache, you
> can use, "CheckCacheOnly".
>
> EclipseLink also allows any "NamedQuery" to cache its results.  If you
> re-execute the same NamedQuery with the same parameters, you will get a
> query cache hit.  The query cache is configured on the query using the query
> hint, "eclipselink.query-results-cache"="true".
>
> See,
> http://www.eclipse.org/eclipselink/api/2.0.1/org/eclipse/persistence/config/QueryHints.html
>
>
> tch wrote:
>>
>> I believe even if EL is hitting the cache you'll still see the SQL in the
>> logs.
>>
>> ./tch
>>
>>
>> On Wed, May 19, 2010 at 8:53 PM, Zarar Siddiqi <zarars@xxxxxxxxx> wrote:
>>
>>> I've already tried the following:
>>>
>>>       Session session =
>>> JpaHelper.getServerSession(em.getEntityManagerFactory());
>>>
>>>        ReadAllQuery q = new ReadAllQuery(Person.class);
>>>        q.setJPQLString("SELECT OBJECT(p) FROM Person p");
>>>        q.addArgument("1");
>>>        q.addArgument("3");
>>>        List args = new ArrayList();
>>>        args.add(activityCode);
>>>        q.cacheQueryResults();
>>>        q.cacheStatement();
>>>        q.setQueryResultsCachePolicy(new QueryResultsCachePolicy(new
>>> TimeToLiveCacheInvalidationPolicy(60000));
>>>        List list = session.executeQuery(q, args);
>>>
>>> Despite this, it still prints the SQL twice in the logs on successive
>>> calls.  This is based on the example shown here:
>>>
>>>
>>> http://wiki.eclipse.org/EclipseLink/Examples/JPA/ORMQueries#A_Simple_ReadAllQuery_Using_JPQL
>>>
>>>
>>>
>>>
>>> On Wed, May 19, 2010 at 6:05 PM, Zarar Siddiqi <zarars@xxxxxxxxx> wrote:
>>> > I'm using 1.2 and have a couple cache related questions.
>>> >
>>> > Do read-all queries (ones using getResultList()) always hit the
>>> database?
>>> >
>>> > As I understand the docs, the "CheckCacheThenDatabase" hit only
>>> > applies to read-object queries (ones using getSingleResult()).  In my
>>> > app, I have a ton of queries that are candidates for caching, but they
>>> > all use getResultList(). I've set an @Cache(expiry=60000) annotation
>>> > on those entities and when I execute them, I keep seeing the queries
>>> > printed in the logs.
>>> >
>>> > To me, this isn't the greatest behaviour since I'm executing the exact
>>> > same query with the exact same parameters.  Shouldn't EclipseLink have
>>> > a way of optimizing this?
>>> >
>>> > Thanks,
>>> > Zarar
>>> >
>>>
>>>
>>>
>>> --
>>> Zarar Siddiqi
>>> 416-737-9024
>>
>>
>
>
> -----
> http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland
> http://www.eclipse.org/eclipselink/
>  EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
> TopLink
> Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink ,
> http://wiki.oracle.com/page/TopLink TopLink
> Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink ,
> http://www.nabble.com/EclipseLink-f26430.html EclipseLink
> Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence
> --
> View this message in context: http://old.nabble.com/Caching-read-all-queries-tp28614962p28741730.html
> Sent from the EclipseLink - Users mailing list archive at Nabble.com.
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>



-- 
Zarar Siddiqi
416-737-9024


Back to the top