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 Roman Pichlik <ro...@systinet.com> on 2006/05/10 18:37:13 UTC

Is Read Only Cache really per session?

Hi,
i found this senetnces in documentation

"Serializable Read/Write Caches

As you may agree, caching per-session as described above may offer 
little benefit to global application performance. Another type of 
read/write cache that can offer a performance benefit to the entire 
application (i.e. not just per session) is a serializable read/write cache."


My multi-thread test show me (iBATIS log contains only one select) that 
Read Only Cahe isn`t per session, but works in the same way as 
Read/Write Cache (All sessions share same cache). Can you explain me that?

Test code:

<cacheModel id="blog-cache" type ="LRU" readOnly="true" serialize="false">
     <flushInterval hours="24"/>
     <flushOnExecute statement="Blog.save"/>
     <flushOnExecute statement="Blog.update"/>
     <flushOnExecute statement="Blog.delete"/>
     <property name="cache-size" value="1000" />
</cacheModel>

<select id="getAll" resultClass="blog" cacheModel="blog-cache">
     select
         blog_id as blogId,
         blog_name as blogName,
         bloger_firstname as blogerFirstName,
         bloger_surname as blogerSurName,
         bloger_email as blogerEmail,
         created
     from
         blogs
</select>

public class ReadOnlyCacheExampleII {

     public static void main(String args[]) throws Exception {
             for (int i = 0; i < 10; i++) {
                 new Client().start();
                 if(i == 0) {
                     Thread.currentThread().sleep(1000);
                 }
             }
     }

      public static class Client extends Thread {
         public void run() {
             for (int i = 0; i < 100; i++) {
                 try{sleep(10*i);}catch(InterruptedException e){};
                 SqlMapSession session = null;
                 try{
                     session = 
SqlMapClientHolder.getSqlMapClient().openSession();
                     Blog blog = (Blog) 
session.queryForList("Blog.getAll" , null).get(0);
                     Blog blog2 = (Blog) 
session.queryForList("Blog.getAll" , null).get(0);

                     if(blog != blog2) {
                         throw new AssertionError();
                     }
                 } catch(SQLException e){
                     e.printStackTrace();
                 } finally{
                    session.close();
                 }
             }
         }
     }
}

thx, Dagi



______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________