2012-10-11 24 views
2

django-compressor甚至在啓用Memcached時仍然輸出COMPRESS_ROOT文件夾中的壓縮文件是否正確?如何在使用memcached時django-compressor仍輸出文件?

在它說的文檔:

對於生產基地,強烈建議使用一個真正的緩存後端,如分佈式緩存,以加快壓縮文件的檢查。

我在Django中的緩存設置正確並正常工作。

CACHES = { 
    'default': { 
     'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache', 
     'LOCATION': '127.0.0.1:11211', 
     } 
} 

什麼,我看到的是,與memcached的啓用,如果我刪除的文件夾STATIC_ROOT,Django的壓縮機不會再重新生成JS/CSS文件。其他人看到這個bahaviour?

回答

1

我面臨類似的問題。爲了解決這個問題,我在我的django應用程序中創建了一個小型django管理命令,用於清除部署期間運行的memcache。

我想如果你依賴memcache來做很多事情,你可能希望做得更加細緻,但是對於我們吹散整個緩存是沒有問題的。

代碼如下:

from django.core.cache import cache 

from django.core.management.base import BaseCommand, CommandError 
import getpass 

class Command(BaseCommand): help = 'Flush the memcache (or whatever the default caching system is)' 

    def handle(self, *args, **options): 
    if ("flush_all" in dir(cache._cache)): 
     cache._cache.flush_all() 
     print "Cache Flush Done." 
    else: 
     print "No-op ... this cache type has no flush" 
相關問題