@@ -0,0 +1,1123 @@
+from django.core.cache import caches%0Afrom django.conf import settings%0Afrom types import MethodType%0A%0Adef get_cache(name='default'):%0A    %22%22%22Returns cache with ttl(key) method added that returns key's time to live %0A    (time left until expiration). It works only for redis and locmem. %0A    For other backends it raises exception.    %0A    %22%22%22%0A    cache = caches%5Bname%5D%0A    if hasattr(cache, 'ttl'):        %0A        return cache    %0A    backend = settings.CACHES.get(name, %7B%7D).get('BACKEND', None)%0A    if backend == 'redis_cache.RedisCache':%0A        def ttl(self, key):%0A            key2 = cache.make_key(key)%0A            t = cache._client.ttl(key2)%0A            return t        %0A    elif backend == 'django.core.cache.backends.locmem.LocMemCache':%0A        def ttl(self, key):%0A            key2 = cache.make_key(key)%0A            t = int(cache._expire_info.get(key2, 0) - time.time())%0A            return t if t%3E0 else 0        %0A    else:%0A        def ttl(self, key):%0A            raise NotImplementedError(%22'ttl' method was added only for redis and locmem cache backends%22)%0A    cache.ttl = MethodType( ttl, cache )    %0A    return cache%0A

Create django_cache_ttl.py