1. 程式人生 > >play framework學習筆記之 使用快取cache

play framework學習筆記之 使用快取cache

Use a cache

例子程式碼

public static void allProducts() {

List<Product> products = Cache.get("products", List.class);

if(products == null) {

products = Product.findAll();

Cache.set("products", products, "30mn");

}

render(products);

}

Cache就是一個快取了資料的Map,你不能保證它永遠生存。

You can connect to a distributed cache by specifying multiple daemon addresses:

你可以連線到分散式的多個快取程序,多個守護程序地址,這些程序可以有jobs來開啟

memcached=enabled
memcached.1.host=127.0.0.1:11211
memcached.2.host=127.0.0.1:11212

https://www.playframework.com/documentation/1.3.x/cache#api