本杰明.巴顿奇事票房:play framework学习笔记之 使用缓存cache

来源:百度文库 编辑:偶看新闻 时间:2024/05/05 07:15:21

play framework学习笔记之 使用缓存cache

分类: play framework 2011-04-18 15:48 105人阅读 评论(0) 收藏 举报

 

Use a cache

例子代码

 

public static void allProducts() {

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

if(products == null) {

products = Product.findAll();

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

}

render(products);

}

 

Cache就是一个缓存了数据的Map,你不能保证它永远生存。

 

Configure memcached

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