mirror of
https://github.com/Hopiu/django-select2.git
synced 2026-04-22 05:54:44 +00:00
The old multiprocessing support was hard to maintain. Since signing and caching are part of `django.core` there is really no need to stick to our own solution. As a result multimachine support and security are now always in place. Fields are stored in Django's cache. The default cache used by select2 is called 'default' but can be cachanged overwriting the setting `SELECT2_CACHE_BACKEND`. Recommended cache backends are memcached, redis or a DB-cache. Refactored AutoResponseView The main reason for this refactoring is the fact that the pagingnation was slow. I dropped major parts of the initial code and wrote a more django-like-approach. Noteabley: - get_results now retuns a QuerySet - This commit drops django 1.6 support in favour of the JsonResponse (Backporting is possible).
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
Shared memory across multiple machines to the heavy ajax lookups.
|
|
|
|
Select2 uses django.core.cache_ to share fields across
|
|
multiple threads and even machines.
|
|
|
|
Select2 uses the cabhe backend defind in the setting
|
|
``SELECT2_CACHE_BACKEND`` [default=``default``].
|
|
|
|
It is advised to always setup a separate cache server for Select2.
|
|
|
|
.. _django.core.cache: https://docs.djangoproject.com/en/dev/topics/cache/
|
|
"""
|
|
from __future__ import absolute_import, unicode_literals
|
|
|
|
from django.core.cache import _create_cache, caches
|
|
|
|
from . import __MEMCACHE_HOST as MEMCACHE_HOST
|
|
from . import __MEMCACHE_PORT as MEMCACHE_PORT
|
|
from . import __MEMCACHE_TTL as MEMCACHE_TTL
|
|
from .conf import settings
|
|
|
|
__all__ = ('cache', )
|
|
|
|
if MEMCACHE_HOST and MEMCACHE_PORT:
|
|
# @todo: Deprecated and to be removed in v5
|
|
location = ':'.join((MEMCACHE_HOST, MEMCACHE_PORT))
|
|
cache = _create_cache('django.core.cache.backends.memcached.MemcachedCache',
|
|
LOCATION=MEMCACHE_HOST, TIMEOUT=MEMCACHE_TTL)
|
|
else:
|
|
cache = caches[settings.SELECT2_CACHE_BACKEND]
|