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
https://www.playframework.com/documentation/1.3.x/cache#api
本文介绍了如何在Play Framework中使用缓存机制提高应用性能。通过示例代码展示了如何获取和设置缓存,并介绍了配置memcached的方法以实现分布式缓存。这对于理解Play Framework中的缓存管理和提高应用程序响应速度至关重要。

5万+

被折叠的 条评论
为什么被折叠?



