IBatis.Net study notes four - cache mode database

It provides a database cache mode in ibatis can improve access efficiency. For some infrequently updated table can be directly used ibatis cache mode.

To use ibatis database cache, as long as the use of configuration files on it, relatively simple to implement:

         < select id = " getcachedaccountsviaresultmap "
                    resultmap
= " account-result "
                    cachemodel
= " account-cache "  >
            select 
*
            from accounts
            order by account_id
        
</ select >

The most important is cachemodel = "account-cache", specified cache way, as is the specific configuration of the local cache:

     < cachemodels >
        
< cachemodel id = " account-cache "  implementation = " memory "  >
            
< flushinterval hours = " 24 " />
            
< flushonexecute  statement = " updateaccountviainlineparameters " />
            
< flushonexecute  statement = " updateaccountviaparametermap " />
      
< flushonexecute  statement = " insertaccountviaparametermap " />
      
< property name = " type "  value = " weak " />
        
</ cachemodel >         
    
</ cachemodels >

Where: implementation = "memory" is to set the cache implementation, you can specify lru, fifo and other, somewhat similar to the memory page replacement policy. memory is a way to use most often.

flushonexecute setting is to update the cache when executing these statements.

Once configured, I conducted a simple test is basically possible, but also have a little problem:
1, the first query result is four records, when I manually insert a record into the database, the second query or 4 records
2, when the system time to the next day I (after 24 hours), and then check, the result is five records
3, when I performed insertaccountviaparametermap statement into a record, then the query is obtained 6 records

in other words: when the system tables never be maintained manually, not modified by a third-party program, you can use the database cache ways to improve efficiency.


Original Address: http://www.cnblogs.com/firstyi/archive/2007/08/20/862826.html

Reproduced in: https: //www.cnblogs.com/zyfking/archive/2009/01/19/1378508.html

Guess you like

Origin blog.csdn.net/weixin_34404393/article/details/93251758