在Python/Django中使用Memcached-问题
我开始使用Memcached使我的网站更快。 对于数据库中的常量数据,我使用以下方法:在Python/Django中使用Memcached-问题,python,database,django,templates,memcached,Python,Database,Django,Templates,Memcached,我开始使用Memcached使我的网站更快。 对于数据库中的常量数据,我使用以下方法: from django.core.cache import cache cache_key = 'regions' regions = cache.get(cache_key) if result is None: """Not Found in Cache""" regions = Regions.objects.all() cache.set(ca
from django.core.cache import cache
cache_key = 'regions'
regions = cache.get(cache_key)
if result is None:
"""Not Found in Cache"""
regions = Regions.objects.all()
cache.set(cache_key, regions, 2592000) #(2592000sekund = 30 dni)
return regions
对于很少的数据更改,我使用信号:
from django.core.cache import cache
from django.db.models import signals
def nuke_social_network_cache(self, instance, **kwargs):
cache_key = 'networks_for_%s' % (self.instance.user_id,)
cache.delete(cache_key)
signals.post_save.connect(nuke_social_network_cache, sender=SocialNetworkProfile)
signals.post_delete.connect(nuke_social_network_cache, sender=SocialNetworkProfile)
这是正确的方法吗
我已经安装了django-memcached-0.1.2,它显示:
Memcached Server Stats
Server Keys Hits Gets Hit_Rate Traffic_In Traffic_Out Usage Uptime
127.0.0.1 15 220 276 79% 83.1 KB 364.1 KB 18.4 KB 22:21:25
有人能解释一下列的意思吗
最后一个问题。
我有一些模板,可以从几个表(关系)中获取许多记录。
所以在我看来,我从一个表中获取记录,并在模板中显示它和其他表中的相关信息。
为非常小的表持续几秒钟生成页面(第二个问题(关于django-memcached-0.1.2状态):