mscerts.net
 
Adaptive Technologies
Adobe AIR Apps
Artistic Software
Communications
Database
Desktop Environment
Documentation
Education
Games
Home Automation
Information Management
Internet
Multimedia
Office
Printing
Programming
Religion
Science
Science and Engineering
Security
System
Terminals
Text Editing&Processing
Utilities
 
 
myGengo 1.2.0
corejet.jira 1.0 Alpha 1
jsoncmd 0.0
correct_pycountry 0.12.2
Monsters 1.0
corejet.core 1.0 Alpha 1
Scope::Container::DBI 0.04
DBIx::DataModel 1.27
Word Golf 0.2.1
Plack::Middleware::LogWarn 0.001002
 
 
 

django-cache-utils 0.5.1

Caching decorator and django cache backend with advanced invalidation ability and dog-pile effect prevention

django-cache-utils is a Django app that provides some utilities to make cache-related work easier:

 * django memcached cache backend with group O(1) invalidation ability, dog-pile effect prevention using MintCache algorythm and project version support to allow gracefull updates and multiple django projects on same memcached instance. Long keys (>250) are truncated and appended with md5 hash.
 * cached decorator. Can be applied to function, method or classmethod. Supports bulk O(1) cache invalidation and meaningful cache keys. Takes function's arguments and full name into account while constructing cache key.

Installation

pip install django-cache-utils

and then:

# settings.py
CACHE_BACKEND = 'cache_utils.group_backend://localhost:11211/'


Usage

from django.db import models
from cache_utils.decorators import cached

class CityManager(models.Manager):

 # cache a method result. 'self' parameter is ignored
 @cached(60*60*24, 'cities')
 def default(self):
 return self.active()[0]

 # cache a method result. 'self' parameter is ignored, args and
 # kwargs are used to construct cache key
 @cached(60*60*24, 'cities')
 def get(self, *args, **kwargs):
 return super(CityManager, self).get(*args, **kwargs)


class City(models.Model):
 # ... field declarations

 objects = CityManager()

 # an example how to cache django model methods by instance id
 def has_offers(self):
 @cached(30)
 def offer_count(pk):
 return self.offer_set.count()
 return history_count(self.pk) > 0

# cache the function result based on passed parameter
@cached(60*60*24, 'cities')
def get_cities(slug)
 return City.objects.get(slug=slug)


# cache for 'cities' group can be invalidated at once
def invalidate_city(sender, **kwargs):
 cache.invalidate_group('cities')
pre_delete.connect(invalidate_city, City)
post_save.connect(invalidate_city, City)


Notes

django-cache-utils use 2 reads from memcached to get a value if 'group' argument is passed to 'cached' decorator:

@cached(60)
def my_func(param)
 return ..

@cached(60, 'my_group')
def my_func2(param)
 return ..

# 1 read from memcached
value1 = my_func(1)

# 2 reads from memcached + ability to invalidate all values at once
value2 = my_func2(2)


Running tests

Add 'cache_utils' to INSTALLED_APPS and run ./manage test cache_utils.

Requirements:

· Python
· Django

  Other
-   htmlpetro 0.2-1
-   django-uuidfield 0.1
-   DjangoOpenInviter 1.0
-   peppercorn 0.3
-   django-mptt 0.3.0
-   htmlpetrol 0.3-2
-   GiPSy Flight Manager 1.6.5
-   Auto Dial 9
-   Email This! 2.3.0
-   Header Spy 1.3.4.1
-   TradeMe Toolbar 0.2.7
-   Hindi Spell Checker 0.1
-   Google Apps Mail Watcher 1.21
-   Apture Highlights 1.4
-   ScribeFire Next 1.3.0.1
-   MySpacePAD: MySpace Photo Album Downloader 0.1
-   Piggy's Page 0.1
-   Quick Link To The World 0.2
-   QflashingLights (GTK) 0.1-3
-   Khmer SBBIC Spelling Checker 1.1
 
 
                mscerts.net