You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by Eva Kwan <Ev...@huskyenergy.com> on 2008/05/13 19:02:38 UTC

iBATIS read/write non-serialize cache

I have a cache model set up like this:

    <cacheModel id="FindAllCache" implementation="LRU" readOnly="false">
      <flushInterval minutes="5"/>
      <property name="CacheSize" value="2"/>
    </cacheModel>

    <select id="FindAll" extends="Base" resultMap="Result" cacheModel="FindAllCache">
    </select>

I have turned on iBATIS logging.  When I execute the select statement more than once within one session, the logs say that there is a cache miss each time.

How do I get a read/write (per session) cache to work?

Re: iBATIS read/write non-serialize cache

Posted by Gilles Bayon <ib...@gmail.com>.
Yes it is


-- 
Cheers,
Gilles

RE: iBATIS read/write non-serialize cache

Posted by Eva Kwan <Ev...@huskyenergy.com>.
Is this the LRU test? (I was looking for it via the FishEye link, but I'm not sure if I found the right one.)   If so, the test seems to be using the default values for readonly and serialized:

<cacheModel id="lru-account-cache" implementation="LRU">
  <flushInterval minutes="5" />
  <property name="CacheSize" value="2" />
</cacheModel>

The configuration that was giving me the cache misses was readOnly="false" and serialize="false".

Eva


From: Gilles Bayon [mailto:ibatis.net@gmail.com]
Sent: Tuesday, May 13, 2008 1:01 PM
To: user-cs@ibatis.apache.org
Subject: Re: iBATIS read/write non-serialize cache

I have just commit a test on the current trunk and didn't see any problem.

2008/05/13 20:53:45:SSS [DEBUG] IBatisNet.DataMapper.Commands.DefaultPreparedCommand - Statement Id: [GetLruCachedAccountsViaResultMap] PreparedStatement : [select *        from Accounts        order by Account_ID]
2008/05/13 20:53:45:SSS [DEBUG] IBatisNet.DataMapper.Configuration.Cache.CacheModel - Cache miss using key '2063825476|9223372033937797411'
2008/05/13 20:53:45:SSS [DEBUG] IBatisNet.DataMapper.SqlMapSession - Open Connection "29220874" to "Microsoft SQL Server, provider V1.0.5000.0 in framework .NET V1.1".
2008/05/13 20:53:45:SSS [DEBUG] IBatisNet.DataMapper.Configuration.Cache.CacheModel - Cache object 'System.Collections.ArrayList' using key '2063825476|9223372033937797411'
2008/05/13 20:53:45:SSS [DEBUG] IBatisNet.DataMapper.SqlMapSession - Close Connection "29220874" to "Microsoft SQL Server, provider V1.0.5000.0 in framework .NET V1.1".
2008/05/13 20:53:45:SSS [DEBUG] IBatisNet.DataMapper.Commands.DefaultPreparedCommand - Statement Id: [GetLruCachedAccountsViaResultMap] PreparedStatement : [select *        from Accounts        order by Account_ID]
2008/05/13 20:53:45:SSS [DEBUG] IBatisNet.DataMapper.Configuration.Cache.CacheModel - Retrieved cached object 'System.Collections.ArrayList' using key '2063825476|9223372033937797411'
2008/05/13 20:53:45:SSS [DEBUG] IBatisNet.DataMapper.Commands.DefaultPreparedCommand - Statement Id: [GetLruCachedAccountsViaResultMap] PreparedStatement : [select *        from Accounts        order by Account_ID]
2008/05/13 20:53:45:SSS [DEBUG] IBatisNet.DataMapper.Configuration.Cache.CacheModel - Retrieved cached object 'System.Collections.ArrayList' using key '2063825476|9223372033937797411'




--
Cheers,
Gilles

Re: iBATIS read/write non-serialize cache

Posted by Gilles Bayon <ib...@gmail.com>.
I have just commit a test on the current trunk and didn't see any problem.

2008/05/13 20:53:45:SSS [DEBUG]
IBatisNet.DataMapper.Commands.DefaultPreparedCommand - Statement Id:
[GetLruCachedAccountsViaResultMap] PreparedStatement : [select *        from
Accounts        order by Account_ID]
2008/05/13 20:53:45:SSS [DEBUG]
IBatisNet.DataMapper.Configuration.Cache.CacheModel - Cache miss using key
'2063825476|9223372033937797411'
2008/05/13 20:53:45:SSS [DEBUG] IBatisNet.DataMapper.SqlMapSession - Open
Connection "29220874" to "Microsoft SQL Server, provider V1.0.5000.0 in
framework .NET V1.1".
2008/05/13 20:53:45:SSS [DEBUG]
IBatisNet.DataMapper.Configuration.Cache.CacheModel - Cache object
'System.Collections.ArrayList' using key '2063825476|9223372033937797411'
2008/05/13 20:53:45:SSS [DEBUG] IBatisNet.DataMapper.SqlMapSession - Close
Connection "29220874" to "Microsoft SQL Server, provider V1.0.5000.0 in
framework .NET V1.1".
2008/05/13 20:53:45:SSS [DEBUG]
IBatisNet.DataMapper.Commands.DefaultPreparedCommand - Statement Id:
[GetLruCachedAccountsViaResultMap] PreparedStatement : [select *        from
Accounts        order by Account_ID]
2008/05/13 20:53:45:SSS [DEBUG]
IBatisNet.DataMapper.Configuration.Cache.CacheModel - Retrieved cached
object 'System.Collections.ArrayList' using key
'2063825476|9223372033937797411'
2008/05/13 20:53:45:SSS [DEBUG]
IBatisNet.DataMapper.Commands.DefaultPreparedCommand - Statement Id:
[GetLruCachedAccountsViaResultMap] PreparedStatement : [select *        from
Accounts        order by Account_ID]
2008/05/13 20:53:45:SSS [DEBUG]
IBatisNet.DataMapper.Configuration.Cache.CacheModel - Retrieved cached
object 'System.Collections.ArrayList' using key
'2063825476|9223372033937797411'




-- 
Cheers,
Gilles

RE: iBATIS read/write non-serialize cache

Posted by Eva Kwan <Ev...@huskyenergy.com>.
LOCAL_READ_WRITE is the option that I'm looking for.

I guess I'll just wait for the response from the .NET team, and in the mean time, use cacheKey.Update(request.Session) as a temporary workaround.

Thanks!
Eva


-----Original Message-----
From: Clinton Begin [mailto:clinton.begin@gmail.com]
Sent: Tuesday, May 13, 2008 11:48 AM
To: user-cs@ibatis.apache.org
Subject: Re: iBATIS read/write non-serialize cache

For future reference, we should probably just have these three options
as configuration for the cache....

LOCAL_READ_WRITE (serializable=false, readOnly=false)
SHARED_READ_ONLY (serializable=false, readOnly=true)
SHARED_READ_WRITE (serializable=true, readOnly=false)

For the record, (serializable=true, readOnly=true) makes no sense, so
there's no need to support it (I think iBATIS for Java ignores the
serializable setting if readonly is true).

Cheers,
Clinton

On Tue, May 13, 2008 at 11:43 AM, Clinton Begin <cl...@gmail.com> wrote:
> Oooohhh....   So here's the thing...
>
>  If you tell iBATIS that:
>
>  A) The objects in the cache will be tinkered with (i.e. read-write,
>  NOT read-only), and
>  B) The objects are not serializable....
>
>  iBATIS has no choice but to localize the cache to your current
>  session.  That said, it should be the session scope (thread/web
>  request etc.), not the iBATIS request scope... Gilles (or anyone on
>  the .NET team)?
>
>  * If you want this cache to be shared among multiple users, and the
>  objects are meant to be updated/changed, then set readOnly= false and
>  serializable=true.
>
>  * If the objects are strictly read-only (immutable by design or by
>  practice, shared or othewise), then set read-only=true and
>  serializable=false.
>
>  * If this cache is only for your current session/user's current web
>  request (not to be confused with iBATIS' request scope --different),
>  or your read-write classes are simply not serializable, then I think
>  your configuration is right, but Gilles and the .NET team need to
>  either change that cacheKey.update(request.SessionScope) or explain
>  their thinking behind its being request scope.
>
>  I hope that makes sense, sorry for the complexity here.  We hope to
>  improve cache configuration in future versions.
>
>  You did a great job tracking down the cause though.  Nice work.  :-)
>
>  Clinton
>
>
>
>  On Tue, May 13, 2008 at 11:26 AM, Eva Kwan <Ev...@huskyenergy.com> wrote:
>  > Adding a parameter didn't seem to help.
>  >
>  >  I'm using version 1.6.1.  When I trace through the iBATIS source, CachingStatement seems to be using the RequestScope as a part of the key for my configuration, and the hashcode for request is different for each of my select calls.
>  >
>  >                 private CacheKey GetCacheKey(RequestScope request)
>  >                 {
>  >                         ...
>  >
>  >                         if (!cacheModel.IsReadOnly && !cacheModel.IsSerializable)
>  >                         {
>  >                                 cacheKey.Update(request);
>  >                         }
>  >                         return cacheKey;
>  >                 }
>  >
>  >  Thanks,
>  >  Eva
>  >
>  >
>  >
>  >
>  >  -----Original Message-----
>  >  From: Clinton Begin [mailto:clinton.begin@gmail.com]
>  >  Sent: Tuesday, May 13, 2008 11:14 AM
>  >  To: user-cs@ibatis.apache.org
>  >  Subject: Re: iBATIS read/write non-serialize cache
>  >
>  >  I think it might be the case of "no parameters"...   for kicks, add a
>  >  parameter to the query to see if that helps.  a simple
>  >  parameterClass="int" should works.
>  >
>  >  Also, which version are you using?  I thought this was fixed...
>  >
>  >  Clinton
>  >
>  >  On Tue, May 13, 2008 at 11:02 AM, Eva Kwan <Ev...@huskyenergy.com> wrote:
>  >  >
>  >  >
>  >  >
>  >  >
>  >  > I have a cache model set up like this:
>  >  >
>  >  >
>  >  >
>  >  >     <cacheModel id="FindAllCache" implementation="LRU" readOnly="false">
>  >  >
>  >  >       <flushInterval minutes="5"/>
>  >  >
>  >  >       <property name="CacheSize" value="2"/>
>  >  >
>  >  >     </cacheModel>
>  >  >
>  >  >
>  >  >
>  >  >     <select id="FindAll" extends="Base" resultMap="Result"
>  >  > cacheModel="FindAllCache">
>  >  >
>  >  >     </select>
>  >  >
>  >  >
>  >  >
>  >  > I have turned on iBATIS logging.  When I execute the select statement more
>  >  > than once within one session, the logs say that there is a cache miss each
>  >  > time.
>  >  >
>  >  >
>  >  >
>  >  > How do I get a read/write (per session) cache to work?
>  >
>

Re: iBATIS read/write non-serialize cache

Posted by Clinton Begin <cl...@gmail.com>.
For future reference, we should probably just have these three options
as configuration for the cache....

LOCAL_READ_WRITE (serializable=false, readOnly=false)
SHARED_READ_ONLY (serializable=false, readOnly=true)
SHARED_READ_WRITE (serializable=true, readOnly=false)

For the record, (serializable=true, readOnly=true) makes no sense, so
there's no need to support it (I think iBATIS for Java ignores the
serializable setting if readonly is true).

Cheers,
Clinton

On Tue, May 13, 2008 at 11:43 AM, Clinton Begin <cl...@gmail.com> wrote:
> Oooohhh....   So here's the thing...
>
>  If you tell iBATIS that:
>
>  A) The objects in the cache will be tinkered with (i.e. read-write,
>  NOT read-only), and
>  B) The objects are not serializable....
>
>  iBATIS has no choice but to localize the cache to your current
>  session.  That said, it should be the session scope (thread/web
>  request etc.), not the iBATIS request scope... Gilles (or anyone on
>  the .NET team)?
>
>  * If you want this cache to be shared among multiple users, and the
>  objects are meant to be updated/changed, then set readOnly= false and
>  serializable=true.
>
>  * If the objects are strictly read-only (immutable by design or by
>  practice, shared or othewise), then set read-only=true and
>  serializable=false.
>
>  * If this cache is only for your current session/user's current web
>  request (not to be confused with iBATIS' request scope --different),
>  or your read-write classes are simply not serializable, then I think
>  your configuration is right, but Gilles and the .NET team need to
>  either change that cacheKey.update(request.SessionScope) or explain
>  their thinking behind its being request scope.
>
>  I hope that makes sense, sorry for the complexity here.  We hope to
>  improve cache configuration in future versions.
>
>  You did a great job tracking down the cause though.  Nice work.  :-)
>
>  Clinton
>
>
>
>  On Tue, May 13, 2008 at 11:26 AM, Eva Kwan <Ev...@huskyenergy.com> wrote:
>  > Adding a parameter didn't seem to help.
>  >
>  >  I'm using version 1.6.1.  When I trace through the iBATIS source, CachingStatement seems to be using the RequestScope as a part of the key for my configuration, and the hashcode for request is different for each of my select calls.
>  >
>  >                 private CacheKey GetCacheKey(RequestScope request)
>  >                 {
>  >                         ...
>  >
>  >                         if (!cacheModel.IsReadOnly && !cacheModel.IsSerializable)
>  >                         {
>  >                                 cacheKey.Update(request);
>  >                         }
>  >                         return cacheKey;
>  >                 }
>  >
>  >  Thanks,
>  >  Eva
>  >
>  >
>  >
>  >
>  >  -----Original Message-----
>  >  From: Clinton Begin [mailto:clinton.begin@gmail.com]
>  >  Sent: Tuesday, May 13, 2008 11:14 AM
>  >  To: user-cs@ibatis.apache.org
>  >  Subject: Re: iBATIS read/write non-serialize cache
>  >
>  >  I think it might be the case of "no parameters"...   for kicks, add a
>  >  parameter to the query to see if that helps.  a simple
>  >  parameterClass="int" should works.
>  >
>  >  Also, which version are you using?  I thought this was fixed...
>  >
>  >  Clinton
>  >
>  >  On Tue, May 13, 2008 at 11:02 AM, Eva Kwan <Ev...@huskyenergy.com> wrote:
>  >  >
>  >  >
>  >  >
>  >  >
>  >  > I have a cache model set up like this:
>  >  >
>  >  >
>  >  >
>  >  >     <cacheModel id="FindAllCache" implementation="LRU" readOnly="false">
>  >  >
>  >  >       <flushInterval minutes="5"/>
>  >  >
>  >  >       <property name="CacheSize" value="2"/>
>  >  >
>  >  >     </cacheModel>
>  >  >
>  >  >
>  >  >
>  >  >     <select id="FindAll" extends="Base" resultMap="Result"
>  >  > cacheModel="FindAllCache">
>  >  >
>  >  >     </select>
>  >  >
>  >  >
>  >  >
>  >  > I have turned on iBATIS logging.  When I execute the select statement more
>  >  > than once within one session, the logs say that there is a cache miss each
>  >  > time.
>  >  >
>  >  >
>  >  >
>  >  > How do I get a read/write (per session) cache to work?
>  >
>

Re: iBATIS read/write non-serialize cache

Posted by Clinton Begin <cl...@gmail.com>.
Oooohhh....   So here's the thing...

If you tell iBATIS that:

A) The objects in the cache will be tinkered with (i.e. read-write,
NOT read-only), and
B) The objects are not serializable....

iBATIS has no choice but to localize the cache to your current
session.  That said, it should be the session scope (thread/web
request etc.), not the iBATIS request scope... Gilles (or anyone on
the .NET team)?

* If you want this cache to be shared among multiple users, and the
objects are meant to be updated/changed, then set readOnly= false and
serializable=true.

* If the objects are strictly read-only (immutable by design or by
practice, shared or othewise), then set read-only=true and
serializable=false.

* If this cache is only for your current session/user's current web
request (not to be confused with iBATIS' request scope --different),
or your read-write classes are simply not serializable, then I think
your configuration is right, but Gilles and the .NET team need to
either change that cacheKey.update(request.SessionScope) or explain
their thinking behind its being request scope.

I hope that makes sense, sorry for the complexity here.  We hope to
improve cache configuration in future versions.

You did a great job tracking down the cause though.  Nice work.  :-)

Clinton

On Tue, May 13, 2008 at 11:26 AM, Eva Kwan <Ev...@huskyenergy.com> wrote:
> Adding a parameter didn't seem to help.
>
>  I'm using version 1.6.1.  When I trace through the iBATIS source, CachingStatement seems to be using the RequestScope as a part of the key for my configuration, and the hashcode for request is different for each of my select calls.
>
>                 private CacheKey GetCacheKey(RequestScope request)
>                 {
>                         ...
>
>                         if (!cacheModel.IsReadOnly && !cacheModel.IsSerializable)
>                         {
>                                 cacheKey.Update(request);
>                         }
>                         return cacheKey;
>                 }
>
>  Thanks,
>  Eva
>
>
>
>
>  -----Original Message-----
>  From: Clinton Begin [mailto:clinton.begin@gmail.com]
>  Sent: Tuesday, May 13, 2008 11:14 AM
>  To: user-cs@ibatis.apache.org
>  Subject: Re: iBATIS read/write non-serialize cache
>
>  I think it might be the case of "no parameters"...   for kicks, add a
>  parameter to the query to see if that helps.  a simple
>  parameterClass="int" should works.
>
>  Also, which version are you using?  I thought this was fixed...
>
>  Clinton
>
>  On Tue, May 13, 2008 at 11:02 AM, Eva Kwan <Ev...@huskyenergy.com> wrote:
>  >
>  >
>  >
>  >
>  > I have a cache model set up like this:
>  >
>  >
>  >
>  >     <cacheModel id="FindAllCache" implementation="LRU" readOnly="false">
>  >
>  >       <flushInterval minutes="5"/>
>  >
>  >       <property name="CacheSize" value="2"/>
>  >
>  >     </cacheModel>
>  >
>  >
>  >
>  >     <select id="FindAll" extends="Base" resultMap="Result"
>  > cacheModel="FindAllCache">
>  >
>  >     </select>
>  >
>  >
>  >
>  > I have turned on iBATIS logging.  When I execute the select statement more
>  > than once within one session, the logs say that there is a cache miss each
>  > time.
>  >
>  >
>  >
>  > How do I get a read/write (per session) cache to work?
>

RE: iBATIS read/write non-serialize cache

Posted by Eva Kwan <Ev...@huskyenergy.com>.
Adding a parameter didn't seem to help.

I'm using version 1.6.1.  When I trace through the iBATIS source, CachingStatement seems to be using the RequestScope as a part of the key for my configuration, and the hashcode for request is different for each of my select calls.

                private CacheKey GetCacheKey(RequestScope request)
                {
                        ...

                        if (!cacheModel.IsReadOnly && !cacheModel.IsSerializable)
                        {
                                cacheKey.Update(request);
                        }
                        return cacheKey;
                }

Thanks,
Eva


-----Original Message-----
From: Clinton Begin [mailto:clinton.begin@gmail.com]
Sent: Tuesday, May 13, 2008 11:14 AM
To: user-cs@ibatis.apache.org
Subject: Re: iBATIS read/write non-serialize cache

I think it might be the case of "no parameters"...   for kicks, add a
parameter to the query to see if that helps.  a simple
parameterClass="int" should works.

Also, which version are you using?  I thought this was fixed...

Clinton

On Tue, May 13, 2008 at 11:02 AM, Eva Kwan <Ev...@huskyenergy.com> wrote:
>
>
>
>
> I have a cache model set up like this:
>
>
>
>     <cacheModel id="FindAllCache" implementation="LRU" readOnly="false">
>
>       <flushInterval minutes="5"/>
>
>       <property name="CacheSize" value="2"/>
>
>     </cacheModel>
>
>
>
>     <select id="FindAll" extends="Base" resultMap="Result"
> cacheModel="FindAllCache">
>
>     </select>
>
>
>
> I have turned on iBATIS logging.  When I execute the select statement more
> than once within one session, the logs say that there is a cache miss each
> time.
>
>
>
> How do I get a read/write (per session) cache to work?

Re: iBATIS read/write non-serialize cache

Posted by Clinton Begin <cl...@gmail.com>.
I think it might be the case of "no parameters"...   for kicks, add a
parameter to the query to see if that helps.  a simple
parameterClass="int" should works.

Also, which version are you using?  I thought this was fixed...

Clinton

On Tue, May 13, 2008 at 11:02 AM, Eva Kwan <Ev...@huskyenergy.com> wrote:
>
>
>
>
> I have a cache model set up like this:
>
>
>
>     <cacheModel id="FindAllCache" implementation="LRU" readOnly="false">
>
>       <flushInterval minutes="5"/>
>
>       <property name="CacheSize" value="2"/>
>
>     </cacheModel>
>
>
>
>     <select id="FindAll" extends="Base" resultMap="Result"
> cacheModel="FindAllCache">
>
>     </select>
>
>
>
> I have turned on iBATIS logging.  When I execute the select statement more
> than once within one session, the logs say that there is a cache miss each
> time.
>
>
>
> How do I get a read/write (per session) cache to work?