Skip to content

Cache machine #

Find similar titles

2회 업데이트 됨.

Edit
  • 최초 작성자
    Sardor
  • 최근 업데이트
    Dragon

Structured data

Category
Etc
Programming
Database

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 %}

Suggested Pages #

0.0.1_20231010_1_v71