Forráskód Böngészése

add clear product cache

abiao 4 éve
szülő
commit
6983de7cd0

+ 5 - 1
go/gopath/src/fohow.com/apps/controllers/railsadmin_controller/cache_controller.go

@@ -37,9 +37,13 @@ func (self *RailsadminController) CleanCache() {
 		k := cache.GetKey(cache.GetProjectById, id)
 		cache.Cache.Delete(k)
 	case t == "package":
-		beego.BeeLogger.Warn("railsadmin after save clean cache: %d", id)
+		beego.BeeLogger.Warn("railsadmin after save clean package cache: %d", id)
 		k := cache.GetKey(cache.GetProductPackagetByPId, id)
 		cache.Cache.Delete(k)
+	case t == "product":
+		beego.BeeLogger.Warn("railsadmin after save clean product cache: %d", id)
+		k := cache.GetKey(cache.GetProductByPId, id)
+		cache.Cache.Delete(k)
 	}
 	self.ServeJSON()
 }

+ 2 - 1
go/gopath/src/fohow.com/apps/models/product_model/product.go

@@ -155,7 +155,8 @@ func GetLatestCount(recommend int64, ptype string, useCache bool) int64 {
 
 //根据商品Id,获取商品信息
 func GetProductById(id int64, useCache bool) *Product {
-	k := fmt.Sprintf("product_model.GetProductById[%d]", id)
+	//k := fmt.Sprintf("product_model.GetProductById[%d]", id)
+	k := cache.GetKey(cache.GetProductByPId, id)
 	if useCache {
 		if v, ok := cache.Cache.Get(k).(*Product); ok {
 			return v

+ 4 - 0
go/gopath/src/fohow.com/cache/init.go

@@ -53,6 +53,8 @@ const (
 
 	//商品
 	GetProductPackagetByPId = "product_model.GetPackageList"
+	GetProductByPId         = "product_model.GetProductById"
+
 	//项目
 	GetProjectById = "project_model.GetProjectById"
 	//默认签章
@@ -114,6 +116,8 @@ func GetKey(key string, params ...interface{}) string {
 		cacheKey = fmt.Sprintf("%s.uId(%d)", key, params[0])
 	case GetProductPackagetByPId:
 		cacheKey = fmt.Sprintf("%s.pId(%d)", key, params[0])
+	case GetProductByPId:
+		cacheKey = fmt.Sprintf("%s.pId(%d)", key, params[0])
 
 	}