`

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,你不能保证它永远生存。

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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics