2011-03-08 42 views
1

此代码:Python的负荷多个对象映射到内存缓存中使用

for num in range(1,4): 
     results = memcache.get("link_" + str(num)) 
     output.write('An anonymous person wrote: <blockquote>%s</blockquote>' % results.date) 
    return output.getvalue() 

这个代码不工作:

results = memcache.get_multi(linkKeys,"link_") 
for results in results: 
    output.write('An anonymous person wrote: <blockquote>%s</blockquote>' % results.date) 
return output.getvalue() 

有人能使用的原因返回memcache.get_multi错误给我解释一下:

Traceback (most recent call last): 
    File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 515, in __call__ 
    handler.get(*groups) 
    File "C:\Main.py", line 28, in get 
    values.write(self.RenderValue()) 
    File "C:\Main.py", line 57, in RenderValue 
    output.write('An anonymous person wrote: <blockquote>%s</blockquote>' % results.date) 
AttributeError: 'str' object has no attribute 'date' 

感谢有人帮我解决这个问题!

回答

0

memcache只能存储pickleable对象。你能安全地腌制GqlQuery结果吗?如果不是,则可能需要先将其转换为dict,然后再将其交给内存缓存。

查看pickle docs,可能还有相关的GAE文档。

您可能还想对此进行基准测试,看看使用memcache是​​否真的有所帮助。

1

结果* s *结果* s * ??