推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
maiziedu
V2EX  ›  Python

Django 中的 FileSystem 缓存配置

  •  
  •   maiziedu · Feb 4, 2017 · 3013 views
    This topic created in 3522 days ago, the information mentioned may be changed or developed.

    配置

    基于文件的 backend 会将每个缓存值分别存储到各个文件中。

    配置 filesystem 缓存:

    BACKEND

    "django.core.cache.backends.filebased.FileBasedCache" //让系统知道我们要将我们的缓存缓存到文件系统中区域

    LOCATION //指定合适的文件夹目录,文件夹目录可以有“/”也可以没有,都将处理成正确的,这个是缓存的目录设置

    设置为合适的文件夹目录

    OPTIONS

    MAX_ENTRIS 默认 300

    CULL_FREQUENCY 默认 3 一般需要设置

    配置——示例一

    (对于 Linux 和 Unix 下,直接指定它的绝对路径)

    CACHES = {

    'default': {

    'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',

    'LOCATION': '/var/tmp/django_cache',

    }

    }

    配置——示例二

    (如果是 Windows ,则写成 Windows 的目录)

    CACHES = {

    'default': {

    'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',

    'LOCATION': 'c:/foo/bar',

    }

    }

    配置——注意

    1 )目录的路径需要绝对路径, Filesystem 缓存会以 root 权限启动 (必须保证系统能够对缓存的目录有访问权限)

    2 )目录路径结尾处的“/”可有可无

    3 )确保目录存在,且 web 服务器的用户对该目录具有读写权限

    原文链接: http://www.maiziedu.com/wiki/django/deploy/

    3 replies  •  2017-02-06 22:00:44 +08:00
    julyclyde
        1
    julyclyde  
       Feb 5, 2017
    一旦使用了 Filesystemcache ,则会面临部署多台服务器的时候 cache 不一致的问题
    AyoCross
        2
    AyoCross  
       Feb 6, 2017
    @julyclyde 还有这一说,能否解释一下。。学习 django 不久,我还以为所有 cache 在表现上只有快慢不同
    julyclyde
        3
    julyclyde  
       Feb 6, 2017
    @AyoCross 多台服务器各有各的“本地文件系统”
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   818 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 20:45 · PVG 04:45 · LAX 13:45 · JFK 16:45
    ♥ Do have faith in what you're doing.