Spring + iBatis + Hessian caching
I have a Hessian serv开发者_如何学Goice on Spring + iBatis working on Tomcat. I'm wondering how to cache results...
I've made the following config in my sqlmap file:
<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>
Then i've done some tests... I have a hessian client application. I'm calling getAccounts several times and after each call it's a query to DBMS.
How to make my service to query DBMS only a first time (after server restart) getAccounts called and for the following calls to use a cache?
Solved. The solution was to add
<settings cacheModelsEnabled="true" />
to my sqlMapConfig file.
精彩评论