Cache machine
#
Find similar titles
- 최초 작성자
- 최근 업데이트
Structured data
- Category
- Etc
- Programming
- Database
Table of Contents
Cache machine #
Cache Machine provides automatic caching and invalidation for Django models through the ORM.
Requirements #
Cache Machine works with Django 1.4-1.8 and Python 2.6, 2.7, 3.3 and 3.4.
How to install #
Get it from pypi:
pip install django-cache-machine
or github:
pip install -e git://github.com/django-cache-machine/django-cache-machine.git#egg=django-cache-machine
Add into settings.py
:
CACHES = {
'default': {
'BACKEND': 'caching.backends.memcached.MemcachedCache',
'LOCATION': [
'server-1:11211',
'server-2:11211',
],
'KEY_PREFIX': 'weee:',
},
}
Cache Manager #
To enable caching for a model, add the CachingManager to that class and inherit from the CachingMixin
.
from django.db import models
from caching.base import CachingManager, CachingMixin
class Zomg(CachingMixin, models.Model):
val = models.IntegerField()
objects = CachingManager()
Template Caching #
{% cache objects %} {# objects is a CachingQuerySet #}
{% for obj in objects %}
...
{% endfor %}
{% endcache %}