You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Larry Meadors <lm...@apache.org> on 2007/06/06 12:59:47 UTC

Re: Cache object reference

On 6/6/07, Meindert <me...@pastelebusiness.com> wrote:
> Is it by design that the object returned from the cache has the same object
> reference as the on in the cache?

Yes, it is. This is intended to be a performance enhancing tweak for
the brave, but in your case it is a misconfiguration.

In your cache definition, you have readonly="true", but are not
modifying the results. You are a very bad boy. Don't do that. :-)

If you set serializable="true" and readonly="false" then the object is
copied before being returned from the cache - assuming that the cached
objects are serializable - if they are not, KABOOM!

Note: If you set serializable="false" and readonly="false", you will
lose a lot of caching benefits, because results will only be cached
for the current iBATIS 'session', which is in 99.999% of cases, not
what you want. Don't do that either. :-)

Larry

Re: Cache object reference

Posted by Larry Meadors <lm...@apache.org>.
<shameless-plug>Ya, it's in the book, buy it! :-)</shameless-plug>

http://www.amazon.com/gp/product/1932394826?ie=UTF8&tag=ai0e-20&link_code=as3&camp=211189&creative=373489&creativeASIN=1932394826

Larry


On 6/6/07, Gwyn Evans <gw...@gmail.com> wrote:
> On Wednesday, June 6, 2007, 11:59:47 AM, Larry <lm...@apache.org> wrote:
>
> > On 6/6/07, Meindert <me...@pastelebusiness.com> wrote:
> >> Is it by design that the object returned from the cache has the same object
> >> reference as the on in the cache?
>
> > In your cache definition, you have readonly="true", but are not
> > modifying the results. You are a very bad boy. Don't do that. :-)
>
> Don't you mean "but are modifying the results"?   :-)
>
> Anyway, for the OP, Larry's obviously too polite, but "iBATIS in
> Action" has a good explanation about this (and a lot else) - See
> section 9.3.4 on p200.
>
> /Gwyn
>
>

Re: Cache object reference

Posted by Gwyn Evans <gw...@gmail.com>.
On Wednesday, June 6, 2007, 11:59:47 AM, Larry <lm...@apache.org> wrote:

> On 6/6/07, Meindert <me...@pastelebusiness.com> wrote:
>> Is it by design that the object returned from the cache has the same object
>> reference as the on in the cache?

> In your cache definition, you have readonly="true", but are not
> modifying the results. You are a very bad boy. Don't do that. :-)

Don't you mean "but are modifying the results"?   :-)

Anyway, for the OP, Larry's obviously too polite, but "iBATIS in
Action" has a good explanation about this (and a lot else) - See
section 9.3.4 on p200.

/Gwyn


RE: Cache object reference

Posted by Meindert <me...@pastelebusiness.com>.
Ah! Excellent that is better then cloning the result object! Thanks!

Must say though, I don't understand the whole caching..
> In your cache definition, you have readonly="true", but are not
> modifying the results. You are a very bad boy. Don't do that. :-)
Readonly="true" is the default so I thought that is the 'normal' setting
I have a readonly cache and are only reading (not modifying) the result,
sounds right doesn't it?
I also tried Readonly="false" but this (without serializable=true) did not
'fix' the issue.

I flush the cache when I do an update. And therefore don't need to write to
the cache? Am I misusing the cache functionality in this way?

The example on page 42 of the developer guide states readOnly="true"
serialize="false", this is a bad configuration?

> because results will only be cached for the current iBATIS 'session'
I'm running iBATIS in a web application, isn't there only one iBATIS
'session'? (When I start the web application for the first time)

Kind Regards
 Meindert


-----Original Message-----
From: larry.meadors@gmail.com [mailto:larry.meadors@gmail.com] On Behalf Of
Larry Meadors
Sent: 06 June 2007 01:00 PM
To: user-java@ibatis.apache.org
Subject: Re: Cache object reference

On 6/6/07, Meindert <me...@pastelebusiness.com> wrote:
> Is it by design that the object returned from the cache has the same
object
> reference as the on in the cache?

Yes, it is. This is intended to be a performance enhancing tweak for
the brave, but in your case it is a misconfiguration.

In your cache definition, you have readonly="true", but are not
modifying the results. You are a very bad boy. Don't do that. :-)

If you set serializable="true" and readonly="false" then the object is
copied before being returned from the cache - assuming that the cached
objects are serializable - if they are not, KABOOM!

Note: If you set serializable="false" and readonly="false", you will
lose a lot of caching benefits, because results will only be cached
for the current iBATIS 'session', which is in 99.999% of cases, not
what you want. Don't do that either. :-)

Larry