コード例 #1
0
ファイル: utils.py プロジェクト: AdrianRibao/drf-extensions
def get_cache(alias):
    # todo: test me
    if get_django_features()['caches_singleton']:
        from django.core.cache import caches
        return caches[alias]
    else:
        from django.core.cache import get_cache as _get_cache
        return _get_cache(alias)
コード例 #2
0
ファイル: utils.py プロジェクト: tume/drf-extensions
def get_cache(alias):
    # todo: test me
    if get_django_features()['caches_singleton']:
        from django.core.cache import caches
        return caches[alias]
    else:
        from django.core.cache import get_cache as _get_cache
        return _get_cache(alias)
コード例 #3
0
ファイル: compat.py プロジェクト: rkirmizi/django-exchange
def get_cache(backend, **kwargs):
    """
    Django cache backend compatibility
    """
    try:
        from django.core.cache import _create_cache
    except ImportError:
        from django.core.cache import get_cache as _get_cache
        return _get_cache(backend, **kwargs)

    cache = _create_cache(backend, **kwargs)
    signals.request_finished.connect(cache.close)
    return cache
コード例 #4
0
def get_cache_backend():
    """
    Compatibilty wrapper for getting Django's cache backend instance
    """
    try:
        from django.core.cache import _create_cache
    except ImportError:
        # Django < 1.7
        from django.core.cache import get_cache as _get_cache
        return _get_cache(settings.DBTEMPLATES_CACHE_BACKEND)

    cache = _create_cache(settings.DBTEMPLATES_CACHE_BACKEND)
    # Some caches -- python-memcached in particular -- need to do a cleanup at the
    # end of a request cycle. If not implemented in a particular backend
    # cache.close is a no-op
    signals.request_finished.connect(cache.close)
    return cache
コード例 #5
0
def get_cache_backend():
    """
    Compatibilty wrapper for getting Django's cache backend instance
    """
    try:
        from django.core.cache import _create_cache
    except ImportError:
        # Django < 1.7
        from django.core.cache import get_cache as _get_cache
        return _get_cache(settings.DBTEMPLATES_CACHE_BACKEND)

    cache = _create_cache(settings.DBTEMPLATES_CACHE_BACKEND)
    # Some caches -- python-memcached in particular -- need to do a cleanup at the
    # end of a request cycle. If not implemented in a particular backend
    # cache.close is a no-op
    signals.request_finished.connect(cache.close)
    return cache
コード例 #6
0
ファイル: utils.py プロジェクト: dinie/django-cacheback
def get_cache(backend, **kwargs):
    """
    Compatibilty wrapper for getting Django's cache backend instance

    original source: https://github.com/vstoykov/django-imagekit/commit/c26f8a0538778969a64ee471ce99b25a04865a8e
    """
    try:
        from django.core.cache import _create_cache
    except ImportError:
        # Django < 1.7
        from django.core.cache import get_cache as _get_cache
        return _get_cache(backend, **kwargs)

    cache = _create_cache(backend, **kwargs)
    # Some caches -- python-memcached in particular -- need to do a cleanup at the
    # end of a request cycle. If not implemented in a particular backend
    # cache.close is a no-op
    signals.request_finished.connect(cache.close)
    return cache