You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by nasseria1 <na...@gmail.com> on 2010/09/23 23:31:56 UTC

How to reset OpenJPA cache

Hi all,
After reading OpenJPA, I could not find a clear way to clear OpenJPA cache.
Is there any API that developers call it to reset entity cache?

Thanks for the attention,
Nasser Fard
-- 
View this message in context: http://openjpa.208410.n2.nabble.com/How-to-reset-OpenJPA-cache-tp5564799p5564799.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: How to reset OpenJPA cache

Posted by Rick Curtis <cu...@gmail.com>.
http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_cache_use_JPA

If you are working on pre-2.0. code you'll have to look at section 1.2.2 and
use the OpenJPA specific APIs.

Thanks,
Rick

On Thu, Sep 23, 2010 at 4:31 PM, nasseria1 <na...@gmail.com> wrote:

>
> Hi all,
> After reading OpenJPA, I could not find a clear way to clear OpenJPA cache.
> Is there any API that developers call it to reset entity cache?
>
> Thanks for the attention,
> Nasser Fard

Re: How to reset OpenJPA cache

Posted by nasseria1 <na...@gmail.com>.
Thanks Kevin,

I am using OpenJPA 1.2, and as I understood, based on the version, clearing
could be different. Therefore, using evictAll() will work for all version.
But for clearing cache from all entity of a special class, I think evict is
a bit complicated and we can use DataCache utility to clear one object from
cache. However, I did not find any sample code about how to obtain
DataCache. I guess DataCache is not supported in the newer versions. But for
us, clearing  Data Cache with DataCache class is enough for us. Can you give
an example, about clearing data cache using DataCache method?

Thanks in advance,
Nasser Fard
-- 
View this message in context: http://openjpa.208410.n2.nabble.com/How-to-reset-OpenJPA-cache-tp5564799p5571493.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: How to reset OpenJPA cache

Posted by Kevin Sutter <kw...@gmail.com>.
Hi Nassar,
On Sat, Sep 25, 2010 at 2:40 PM, nasseria1 <na...@gmail.com> wrote:

>
> Using the discussed methods I selected "cache.evictAll()" to clear the
> second level cache in OpenJPA, and I guess it worked, although I am not
> sure. First, is there any way to be sure that the cache is cleared in a
> simple case? for e.g. is there any count method to measure the
> functionality
> of evict() or evictAll() methods? To be more clear, we want to clear the
> second level cache in a certain way.
>

In the reference that Rick provided [1], there are a couple of ways to
determine whether the clear worked or not.  Since it sounds like you are
using JPA 2.0, then the easiest way is to just call the contains(Class, id)
method.  Or, you could use the cache statistics methods, also documented in
the reference.


> And finally, as we discussed, clearing the cache by evict() methods, has
> any
> side effect or any other practice that may be overlooked by programmers? I
> mean any aspect that can affect performance or even integrity of data?
>

The use of the second level cache is meant for performance reasons.  But,
there is always the chance that you could end up with stale data.
Especially if you have other applications affecting the database
simultaneously.  You can not affect the integrity of data by clearing a
cache.  But, depending on your application, you could affect performance.
Some experimentation and analysis will be required to get your usage
correct.

Good luck,
Kevin

[1]
http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_cache_use_JPA

Thanks for giving any idea,
> Nasser Fard
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/How-to-reset-OpenJPA-cache-tp5564799p5570602.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Re: How to reset OpenJPA cache

Posted by nasseria1 <na...@gmail.com>.
Thanks all for replies,

Using the discussed methods I selected "cache.evictAll()" to clear the
second level cache in OpenJPA, and I guess it worked, although I am not
sure. First, is there any way to be sure that the cache is cleared in a
simple case? for e.g. is there any count method to measure the functionality
of evict() or evictAll() methods? To be more clear, we want to clear the
second level cache in a certain way.

And finally, as we discussed, clearing the cache by evict() methods, has any
side effect or any other practice that may be overlooked by programmers? I
mean any aspect that can affect performance or even integrity of data?

Thanks for giving any idea,
Nasser Fard
-- 
View this message in context: http://openjpa.208410.n2.nabble.com/How-to-reset-OpenJPA-cache-tp5564799p5570602.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: How to reset OpenJPA cache

Posted by Kevin Sutter <kw...@gmail.com>.
It depends on which cache is being requested to be cleared...

The EntityManager / Persistence Context can be cleared via the em.clear()
invocation.  This is also known as a Level 1 cache.

If you are asking about the Level 2 cache, then as Rick pointed out, it
depends on whether you are using pre-JPA 2.0 level code.  Prior to JPA 2.0,
there was no defined mechanism for working with a L2 cache.  Thus, OpenJPA
1.x provided their own API for performing this function.

Kevin

On Thu, Sep 23, 2010 at 7:54 PM, C N Davies <cn...@cndavies.com> wrote:

> Em.clear();  seems to do the job for me.
>
> chris
>
>
>
> -----Original Message-----
> From: nasseria1 [mailto:nasser.fard@gmail.com]
> Sent: Friday, 24 September 2010 7:32 AM
> To: users@openjpa.apache.org
> Subject: How to reset OpenJPA cache
>
>
> Hi all,
> After reading OpenJPA, I could not find a clear way to clear OpenJPA cache.
> Is there any API that developers call it to reset entity cache?
>
> Thanks for the attention,
> Nasser Fard
> --
> View this message in context:
>
> http://openjpa.208410.n2.nabble.com/How-to-reset-OpenJPA-cache-tp5564799p556
> 4799.html<http://openjpa.208410.n2.nabble.com/How-to-reset-OpenJPA-cache-tp5564799p556%0A4799.html>
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
>

RE: How to reset OpenJPA cache

Posted by C N Davies <cn...@cndavies.com>.
Em.clear();  seems to do the job for me.

chris



-----Original Message-----
From: nasseria1 [mailto:nasser.fard@gmail.com] 
Sent: Friday, 24 September 2010 7:32 AM
To: users@openjpa.apache.org
Subject: How to reset OpenJPA cache


Hi all,
After reading OpenJPA, I could not find a clear way to clear OpenJPA cache.
Is there any API that developers call it to reset entity cache?

Thanks for the attention,
Nasser Fard
-- 
View this message in context:
http://openjpa.208410.n2.nabble.com/How-to-reset-OpenJPA-cache-tp5564799p556
4799.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.