slim3のmemchacheを使ってみる。
slim3でMemchacheが簡単に使えるようになってたっぽいので使ってみる。
こんな感じでよいのかな。。
public Coupon getCouponForCache(Integer id){ Coupon coupon = Memcache.get("CACHEKEY" + id); if(coupon != null) return coupon; // Datastoreから取得する coupon = getCoupon(id); if(coupon != null) Memcache.put("CACHEKEY" + id, coupon); return coupon; }
※2/21 修正(getの際のキャストは不要)
Coupon coupon = (Coupon)Memcache.get("CACHEKEY" + id); ⇒ Coupon coupon = Memcache.get("CACHEKEY" + id);