App Engine で初めて memcache を使用しようとしましたが、「PicklingError」が発生しました。
memcache を最初に試したのは、データストアからコンテンツを取得するサイトのホームページです。
def get(self):
content = memcache.get('home:content')
if content is None:
all_content = Content.all()
all_content.order("-views")
all_content.filter('published =', True)
content = all_content.run(batch_size=5, limit=5)
memcache.add(key='home:content', value=content, time=120)
(これは、コンテンツ Query オブジェクトを memcache に入れようとしなくても問題なく動作することに注意してください。最後の行 (memcache.add...) でヒットするエラーは次のとおりです。
PicklingError: Pickling of datastore_query.Batcher is unsupported.
コンテンツのモデルは次のとおりです。
class Content(db.Model):
category = db.StringProperty(required = True)
content_type = db.StringProperty(required = True)
published = db.BooleanProperty(default = False)
title = db.StringProperty(required = True)
abstract = db.TextProperty(required = True)
summary = db.TextProperty(required = True)
URL = db.LinkProperty(required = True)
youtube_id = db.StringProperty(required = False)
thumbnail = db.LinkProperty(required = True)
post_author = db.StringProperty(required = True)
author_url = db.LinkProperty(required = False)
date_post = db.DateTimeProperty(required = True, auto_now_add = True)
date_source = db.DateTimeProperty(required = False)
# todo: split out to use decent shardedcounter approach
views = db.IntegerProperty(default = 0)
up_votes = db.IntegerProperty(default = 0)
down_votes = db.IntegerProperty(default = 0)
def votes(self):
return self.up_votes - self.down_votes
PicklingError とは何か、それが Query オブジェクトを memcache に格納しようとすることにどのように関係するのかを理解するのに苦労しています。私の質問: 私は何を間違っていますか? これは、イテレータをキャッシュしようとしているからですか? Query オブジェクトをキャッシュし、ページの読み込みごとに .run() を呼び出す必要があることに価値はありますか?