示例#1
0
文件: cache.go 项目: jack0888/go-user
func removeFromCache(userId int64) (err error) {
	if err = mc.Client().Delete(mc.UserCacheKey(userId)); err != nil {
		if err == memcache.ErrCacheMiss {
			err = nil
		}
		return
	}
	return
}
示例#2
0
文件: cache.go 项目: jack0888/go-user
// 从缓存里获取 user 信息, 如果没有找到返回 ErrNotFound.
func getFromCache(userId int64, user *User) (err error) {
	item, err := mc.Client().Get(mc.UserCacheKey(userId))
	if err != nil {
		if err == memcache.ErrCacheMiss {
			err = ErrNotFound
		}
		return
	}
	return json.Unmarshal(item.Value, user)
}
示例#3
0
文件: cache.go 项目: jack0888/go-user
func putToCache(user *User) (err error) {
	userBytes, err := json.Marshal(user)
	if err != nil {
		return
	}
	mcItem := memcache.Item{
		Key:   mc.UserCacheKey(user.Id),
		Value: userBytes,
	}
	return mc.Client().Set(&mcItem)
}