我目前正在開發一個非常類似的網站給你也在Django。 我將查詢集存儲在緩存中,其中緩存鍵是搜索參數的urlencoded字符串 - 這樣,如果有人執行相同的搜索,則無需重複昂貴的查詢即可獲得相同的結果。
就你而言,你可以從url生成參數列表。
form = form_class(request.POST)
if form.is_valid():
cd = form.cleaned_data
persons = .... #expensive queries that fetch the results of search
cache_id = urlencode(cd.items())
#create md5 hash to use in link to results
cache_id = hashlib.md5(cache_id).hexdigest()
cache.set(cache_id, persons, CACHE_TIMEOUT)
#also store form data in cache, so the form can be easily reconstructed from cache id
cache.set(cache_id+'_form', request.POST, CACHE_TIMEOUT)
這樣做的問題是查詢結果可能會因頁面而異。 – 2009-12-29 18:21:16