【发布时间】:2010-05-24 18:12:23
【问题描述】:
我开始使用 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(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
有人能解释一下列的含义吗?
最后一个问题。 我有模板,我从几个表(关系)中获取许多记录。 因此,在我看来,我从一张表中获取记录,并在模板中显示它以及其他人的相关信息。 为非常小的表(
【问题讨论】:
标签: python database django templates memcached