openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin Sutter <kwsut...@gmail.com>
Subject Re: L1 and L2cache.
Date Thu, 10 Nov 2011 14:35:47 GMT
Hi Ravi,
You don't mention anything about transactions or persistence contexts in
your description, so I'm not sure when things are getting cleared out
naturally.

The normal path of finding an entity is through the Persistence Context (L1
cache), then the L2 cache (if configured), then the database.  The idea
being is that even if you get an "old" copy of the data at least it will be
discovered if you attempt to make changes to it (optimistic locking).  If
you want to force the app to get an updated copy, then you have to clear
out the respective cache of the given entity.

You mentioned that turning off the L2 cache should be forcing OpenJPA to
the database.  Not if you still have that Entity instance in your L1 cache.

I would try your scenario with turning on Trace so that you can see where
the "old" data is coming from.  My guess is this entity still exists in
your L1 cache.  You can clear that by either closing or clearing the EM.
Depending on the version of OpenJPA you are using, you could also detach
the specific entity from your persistence context.

Hope this helps,
Kevin

On Wed, Nov 9, 2011 at 7:00 PM, Ravi P Palacherla <
ravi.palacherla@oracle.com> wrote:

> Hi,
>
> I have a question about L1 cache refresh.
>
> Lets say I have two Entity Managers in my application.
>
> I have a simple JPAEntity entity that has id and name values.
>
> Sequence of steps in the app:
> --------------------------------
> EntityManager EM1 does a query for JPAEntity with id=1.
> EntityManager EM2 does a query for same JPAEntity with id=1.
> EM1 updates name from "old" to "new"
> Now when EM2 does the query again with id=1, it is showing the value of
> name
> as "old" but not "new"
>
> I disabled DataCache and QueryCache which means that EM2's query goes to
> database but it still is showing old values. Reason I think is because
> EM2's
> cache (L1cache) is not updated with "new" value.
>
> Is my understanding correct ?
> If yes, then is there a way I can refresh EM2's cache other than using
> evict() or refresh() call ?
>
> Regards,
> Ravi.
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/L1-and-L2cache-tp6980197p6980197.html
> Sent from the OpenJPA Developers mailing list archive at Nabble.com.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message