0

私が提起した以前の質問から続けています(以下のリンク)

Spring MVC - サーバーの起動時にデータベースから参照データを取得する

以前の投稿でアドバイスを受けた後、参照データをロードするために使用できると思うアプローチは、ArticleController (私のコントローラー クラス) に以下のメソッドを追加することです。

    @ModelAttribute
    public void populateModel(@RequestParam String number, Model model) {
        model.addAttribute("countryList", articleService.getCountryList());
        model.addAttribute("skillsList", articleService.getSkillsList());
    }

次に、以下のように休止状態の二次キャッシュを使用します。

    @Entity
    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
    public class Country {
        ...
    }

スキルクラスも同様

3つの質問があります

  1. populateModel メソッド (@ModelAttribute) は 1 回だけ実行されますか? つまり、ArticleController クラスで最初の @RequestMapping メソッドを実行する前に (複数のセッションのすべてのリクエストについて - ログ トレースで、サーバーの起動時に ArticleController が初期化されるのを見ました)?
  2. 2 番目のレベルのキャッシュを実現するために、私が言及した以上のことを行う必要がありますか? (コントリ リストとスキル リストは、2 つの別々のテーブルの純粋な読み取り専用データです)
  3. 私が見逃したインプポイントとあなたはアドバイスすることができます.
4

2 に答える 2

0
  1. No. The method will be called for every request, as explained in the documentation. BTW, where would it find the request parameter (that you don't use, BTW) if it was called only once?

  2. If you don't enable the query cache in addition to the second-level cache, and make the queries cachable, then Hibernate will execute a SQL query to load the country IDs from the database every time, and then load the entities themselves from the second-level cache. If the query cache is enabled and the queries are cachable, then Hibernate will execute a single query to load all the countries in the cache, and won't execute any query anymore afterwards (at least, for the TTL of the cache region)

  3. I think I have already done what I could do :-). You could read the following article for a better understanding.

于 2012-12-02T13:11:56.243 に答える