mirror of
https://github.com/Hopiu/django-cachalot.git
synced 2026-05-17 17:11:06 +00:00
Adds a CACHALOT_CACHE setting.
This commit is contained in:
parent
bc27896eb9
commit
ec89949043
3 changed files with 26 additions and 6 deletions
16
README.rst
16
README.rst
|
|
@ -38,6 +38,21 @@ Usage
|
|||
#. Enjoy!
|
||||
|
||||
|
||||
Settings
|
||||
........
|
||||
|
||||
================== ============= ==============================================
|
||||
Setting Default value Description
|
||||
================== ============= ==============================================
|
||||
``CACHALOT_CACHE`` ``'default'`` Name of the cache from |CACHES|_ used by
|
||||
django-cachalot
|
||||
================== ============= ==============================================
|
||||
|
||||
|
||||
.. |CACHES| replace:: ``CACHES``
|
||||
.. _CACHES: https://docs.djangoproject.com/en/1.7/ref/settings/#std:setting-CACHES
|
||||
|
||||
|
||||
Limits
|
||||
------
|
||||
|
||||
|
|
@ -99,7 +114,6 @@ For version 1.0
|
|||
- Handle multiple databases
|
||||
- Add invalidation on migrations in Django 1.7 (& South?)
|
||||
- Add a ``CACHALOT_ENABLED`` setting
|
||||
- Add a setting to choose a cache other than ``'default'``
|
||||
|
||||
In a more distant future
|
||||
........................
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from __future__ import unicode_literals
|
|||
from collections import Iterable
|
||||
import re
|
||||
|
||||
from django.core.cache import cache as django_cache
|
||||
from django.core.cache import get_cache as get_django_cache
|
||||
from django.db import connection
|
||||
from django.db.models.query import EmptyResultSet
|
||||
from django.db.models.sql.compiler import (
|
||||
|
|
@ -12,6 +12,7 @@ from django.db.models.sql.compiler import (
|
|||
SQLInsertCompiler, SQLUpdateCompiler, SQLDeleteCompiler)
|
||||
from django.db.models.sql.where import ExtraWhere
|
||||
from django.db.transaction import Atomic
|
||||
from .settings import CACHALOT_CACHE
|
||||
|
||||
|
||||
COMPILERS = (SQLCompiler,
|
||||
|
|
@ -94,8 +95,7 @@ TRANSACTION_CACHES = []
|
|||
class AtomicCache(dict):
|
||||
def __init__(self):
|
||||
super(AtomicCache, self).__init__()
|
||||
self.parent_cache = (TRANSACTION_CACHES[-1] if TRANSACTION_CACHES
|
||||
else django_cache)
|
||||
self.parent_cache = get_cache()
|
||||
self.to_be_deleted = set()
|
||||
|
||||
def get(self, k, default=None):
|
||||
|
|
@ -141,7 +141,9 @@ class AtomicCache(dict):
|
|||
def get_cache():
|
||||
if TRANSACTION_CACHES:
|
||||
return TRANSACTION_CACHES[-1]
|
||||
return django_cache
|
||||
# TODO: Replace with django.core.cache.caches[CACHALOT_CACHE]
|
||||
# when we drop Django 1.6 support.
|
||||
return get_django_cache(CACHALOT_CACHE)
|
||||
|
||||
|
||||
def _patch_orm_read():
|
||||
|
|
@ -237,7 +239,7 @@ def _unpatch_atomic():
|
|||
def _patch_test_db():
|
||||
def patch(original):
|
||||
def inner(*args, **kwargs):
|
||||
django_cache.clear()
|
||||
get_cache().clear()
|
||||
return original(*args, **kwargs)
|
||||
|
||||
inner.original = original
|
||||
|
|
|
|||
4
cachalot/settings.py
Normal file
4
cachalot/settings.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
from django.conf import settings
|
||||
|
||||
|
||||
CACHALOT_CACHE = getattr(settings, 'CACHALOT_CACHE', 'default')
|
||||
Loading…
Reference in a new issue