英文:
Is memcache working in go on appengine?
问题
我有一个应用程序,尝试将小图片(小于50kB)存储在memcache中,但每次调用memcache.Set()都会出现错误memcache: server error
。
我使用的是共享memcache类,所以我知道没有服务保证,但目前我根本没有服务。
这是创建项目并调用memcache的代码片段。ctx
是请求的appengine上下文。memkey
是我的键(一个字符串)。img_data
是包含数据的字符串。
这段代码在本地开发环境中运行良好。
cache_item = &memcache.Item{
Key: memkey,
Value: bytes.NewBufferString(img_data).Bytes(),
}
err = memcache.Set(ctx, cache_item)
if err != nil {
ctx.Infof("无法将图像存储在memcache中:%s", err)
}
英文:
I have an app that tries to store small images (less than 50kB) in memcache, but each call to memcache.Set() results in an error memcache: server error
.
I'm on the shared memcache class, so I understand there is no service guarantee, but currently I have no service at all.
Is it a temporary outage? Am I just unlucky?
Here is the piece of code creating an item and calling memcache. ctx
is the appengine context for the request. memkey
is my key (a string). img_data
is a string with my data.
This code works well in the local dev environment.
cache_item = &memcache.Item{
Key: memkey,
Value: bytes.NewBufferString(img_data).Bytes(),
}
err = memcache.Set(ctx, cache_item)
if err != nil {
ctx.Infof("Could not store image in memcache: %s", err)
}
答案1
得分: 0
如果问题仍然存在,请提交一个错误报告,但我怀疑这只是一个暂时性的问题。
顺便说一下,你的Value初始化器过于复杂了。下面的代码可以达到同样的效果:
cache_item = &memcache.Item{
Key: memkey,
Value: []byte(img_data),
}
英文:
If it's still happening, file a bug, but I suspect it was just a transient problem.
Incidentally, your Value initialiser is unnecessarily complex. This would work the same:
cache_item = &memcache.Item{
Key: memkey,
Value: []byte(img_data),
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论