2

Django キャッシュ API でオブジェクトを手動で設定しようとしていますが、失敗します (酸洗いが原因だと思いますか?) オブジェクトはサードパーティから提供されたもので、私のコードは次のとおりです。

def index(request, template_name="mytemplate.htm"):
    user_list = cache.get("user_list_ds")
    if user_list is None:
            # this is the expensive bit I'm trying to cache
            # given to me by a third part
        user_list = graffiti.user_list("top", 100).responseObj().blocks()
        cache.set("user_list_ds", user_list, 10*60) # 10 minutes

    return render_to_response(template_name, { 'user_list' : user_list,}, context_instance = RequestContext(request))

これを実行するとエラーが発生します。

Can't pickle <type 'etree._Element'>: import of module etree failed
in -    cache.set("user_list_ds", user_list, 10*60) # 10 minutes 

私はPythonに非常に慣れていません。これを解決する最善の方法を考えています。最初に何かをピクルする必要がありますか?

4

1 に答える 1

2

をインストールする必要があるようです。ElementTreeこれは、操作がモジュールpickleのインポートを試みて失敗したためです。etree

更新: さらに詳しく見てみると、実際にドキュメント ノードをキャッシュしようとしていますか? ノードからのデータをキャッシュしようとしている場合は、現在 に保存している値を処理する必要がある可能性がありますuser_list

于 2009-10-23T20:34:44.760 に答える