【问题标题】:How come django-compressor still output a file when memcached is used?django-compressor 为何在使用 memcached 时仍会输出文件?
【发布时间】:2012-10-02 17:00:20
【问题描述】:

即使启用了 Memcached,django-compressor 仍然在 COMPRESS_ROOT 文件夹中输出压缩文件是否正确?

在文档中它说:

对于生产站点,强烈建议使用真正的缓存后端,例如 memcached,以加快压缩文件的检查速度。

我在 Django 中的缓存设置正确并且可以正常工作。

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

我看到的是,启用 memcached 后,如果我删除 STATIC_ROOT 文件夹,django-compressor 将不再重新生成 js/css 文件。其他人看到这种行为吗?

【问题讨论】:

    标签: django-compressor


    【解决方案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"
    

    【讨论】:

      猜你喜欢
      • 2012-02-12
      • 2014-09-27
      • 2013-05-13
      • 1970-01-01
      • 1970-01-01
      • 2011-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多