Andres Vargas - zodman

Limpiar cache(memcached) de django en una vista

from django.core.urlresolvers import reverse from django.http import HttpResponseRedirect from django.contrib import messages

def clear_cache(request): """Clears the complete cache. """ # memcached try: cache._cache.flush_all() except AttributeError: pass

<span style="color: #0000aa">try</span>:
    cache._cache.clear()
<span style="color: #0000aa">except</span> AttributeError:
    <span style="color: #0000aa">pass</span>
<span style="color: #0000aa">try</span>:
    cache._expire_info.clear()
<span style="color: #0000aa">except</span> AttributeError:
    <span style="color: #0000aa">pass</span>
messages.info(request,<span style="color: #aa5500">&quot;Cache Cleared&quot;</span>)
<span style="color: #0000aa">return</span> HttpResponseRedirect(reverse(<span style="color: #aa5500">&quot;admin:index&quot;</span>))