2010-04-18 57 views
0

我在Spring + iBatis上使用Tomcat的Hessian服務。 我不知道如何緩存結果...Spring + iBatis + Hessian緩存

我做了以下配置在我的SqlMap文件:

<sqlMap namespace="Account"> 

<cacheModel id="accountCache" type="MEMORY" readOnly="true" serialize="false"> 
    <flushInterval hours="24"/> 
    <flushOnExecute statement="Account.addAccount"/> 
    <flushOnExecute statement="Account.deleteAccount"/> 
    <property name="reference-type" value="STRONG" /> 
</cacheModel> 

<typeAlias alias="Account" type="domain.Account" /> 

    <select id="getAccounts" resultClass="Account" cacheModel="accountCache"> 
     fix all; 
     select id, name, pin from accounts; 
    </select> 

    <select id="getAccount" parameterClass="Long" resultClass="Account" cacheModel="accountCache"> 
     fix all; 
     select id, name, pin from accounts where id=#id#; 
    </select> 

    <insert id="addAccount" parameterClass="Account"> 
    fix all; 
     insert into accounts (id, name, pin) values (#id#, #name#, #pin#); 
    </insert> 

    <delete id="deleteAccount" parameterClass="Long"> 
     fix all; 
     delete from accounts where id = #id#; 
    </delete> 
</sqlMap> 

然後我做了一些測試...我有一個客戶端麻袋應用。我幾次調用getAccounts,並且在每次調用之後它都是對DBMS的查詢。

如何使我的服務僅在第一次(服務器重新啓動後)查詢DBMS時調用getAccounts並針對以下調用使用緩存?

回答

0

已解決。解決方案是添加到我的sqlMapConfig文件

<settings cacheModelsEnabled="true" />