5.7 Cache

2022-07-11 10:20 更新

ActiveRecord 可以使用緩存以大大提高性能,以下代碼是 Cache 使用示例:

public void list() {
List<Blog> blogList = Blog.dao.findByCache("cacheName", "key", "select * from blog");
setAttr("blogList", blogList).render("list.html");
}

上例 findByCache 方 法 中 的 cacheName 需 要 在 ehcache.xml 中配置 如: <cache name="cacheName" …> 。 此 外 Model.paginateByCache(…) 、 Db.findByCache(…) 、 Db.paginateByCache(…)方法都提供了 cache 支持。在使用時,只需傳入 cacheName、key 以及 在 ehccache.xml 中配置相對應(yīng)的 cacheName 就可以了。

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號