0

我在 Spring + iBatis 上有一个 Hessian 服务,在 Tomcat 上工作。我想知道如何缓存结果...

我在我的 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 的查询。

如何使我的服务仅在第一次(服务器重新启动后)调用 getAccounts 并为以下调用使用缓存来查询 DBMS?

4

1 回答 1

0

解决了。解决方案是添加

<settings cacheModelsEnabled="true" />

到我的 sqlMapConfig 文件。

于 2010-04-18T17:28:57.890 回答