nutz工程里带的wkcache使用的是redis,需要先安装redis。
@IocBean
public class HomeController {
@Inject
private JedisAgent jedisAgent;
@At
@Ok("beetl:/public/site/index.html")
public void index(HttpServletRequest req,@Param("pid") String pid) {
Jedis jedis= jedisAgent.getResource();
String ticket= jedis.get("ticket");//取cache
if(ticket==null){
jedis.append("ticket",pid);//写入cache
jedis.expire("ticket",2);//设置cache过期时间,单位为秒
req.setAttribute("ticket","值"+pid+"已写入cache");
}
else {
req.setAttribute("ticket","cache里的数据:"+ticket);
}
jedis.close();//关闭
}
}