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

    技术2022-05-19  30

     

    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


    最新回复(0)