我目前正在开发一个非常类似的网站给你也在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