Using Memcached in Python/Django - questions.
- by Thomas
I am starting use Memcached to make my website faster.
For constant data in my database I use this:
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
For seldom changed data I use signals:
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)
Is it correct way?
I installed django-memcached-0.1.2, which show me:
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
Can sombody explain what columns means?
And last question.
I have templates where I am getting much records from a few table (relationships).
So in my view I get records from one table and in templates show it and related info from others.
Generating page last a few seconds for very small table (<100records).
Is it some easy way to cache queries from templates?
Have I to do some big structure in my view (with all related tables), cache it and send to template?