2
我想在Django緩存API中手動設置一個對象但它失敗(我認爲是酸洗?) 對象是由我給出的第三方,我的代碼是:在Django緩存API中設置對象由於pickle錯誤而失敗
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很陌生,我想知道如何最好地解決這個問題,我需要先醃製什麼?
你說得對,我不得不改變我們試圖緩存到正常的Python列表中的數據的類型。 – 2009-10-27 00:31:34