Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » How to configure query cache invalidation with JPA queries?
How to configure query cache invalidation with JPA queries? [message #386054] Mon, 23 March 2009 11:34 Go to next message
Torben Putkonen is currently offline Torben PutkonenFriend
Messages: 34
Registered: July 2009
Member
Query cache seems to work nice with cache-usage hint
CheckCacheThenDatabase. However, I need to be able to invalidate cached
queries after a timeout.

EclipseLink documentation contains this example:

readQuery.setQueryResultsCachePolicy(
new QueryResultsCachePolicy(new
TimeToLiveCacheInvalidationPolicy(1000))
);

Our code is currently fully JPA compliant, but we would like to use some
EclipseLink extensions like the query cache. Because we are currently
getting the javax.persistence.Query objects from EntityManager's
createNamedQuery() method, is there a way to set invalidation policy for
them without completely rewriting query code?
Re: How to configure query cache invalidation with JPA queries? [message #386058 is a reply to message #386054] Mon, 23 March 2009 13:56 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

In EclipseLink 1.1 you can configure the query cache, and invalidation
using query hints in any NamedQuery.

The list of query hints are defined here:
http://www.eclipse.org/eclipselink/api/1.1/org/eclipse/persi stence/config/QueryHints.html

The ones for the query cache are:
"eclipselink.query-results-cache"
"eclipselink.query-results-cache.expiry"
"eclipselink.query-results-cache.size"

The cache-usage option is for the object cache however, not the query
cache. For the object cache you can set the invalidation using the @Cache
annotation, EclipseLink orm.xml, or persistence.xml properties.

---
James
http://www.nabble.com/EclipseLink---Users-f26658.html


James : Wiki : Book : Blog : Twitter
Re: How to configure query cache invalidation with JPA queries? [message #386065 is a reply to message #386058] Tue, 24 March 2009 09:21 Go to previous message
Torben Putkonen is currently offline Torben PutkonenFriend
Messages: 34
Registered: July 2009
Member
Thanks James! I upgraded to release 1.1.

Cache seems to work now the way I wanted, by adding one hint to the query:
query.setHint(QueryHints.CACHE_USAGE, CacheUsage.CheckCacheThenDatabase);

And one annotation to the Entity:
@Cache ( expiry=100000 )
Previous Topic:mapping problem: entity as join table
Next Topic:Optimistic locking without EclipseLink dependency in my domain objects?
Goto Forum:
  


Current Time: Mon Jan 20 13:24:23 GMT 2025

Powered by FUDForum. Page generated in 0.04111 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top