Python werkzeug.contrib.cache 模块,FileSystemCache() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用werkzeug.contrib.cache.FileSystemCache()

项目:oa_qian    作者:sunqb    | 项目源码 | 文件源码
def test_set_get(self):
        tmp_dir = tempfile.mkdtemp()
        try:
            c = cache.FileSystemCache(cache_dir=tmp_dir)
            for i in range(3):
                c.set(str(i), i * i)
            for i in range(3):
                result = c.get(str(i))
                assert result == i * i
        finally:
            shutil.rmtree(tmp_dir)
项目:oa_qian    作者:sunqb    | 项目源码 | 文件源码
def test_filesystemcache_prune(self):
        THRESHOLD = 13
        tmp_dir = tempfile.mkdtemp()
        c = cache.FileSystemCache(cache_dir=tmp_dir, threshold=THRESHOLD)
        for i in range(2 * THRESHOLD):
            c.set(str(i), i)
        cache_files = os.listdir(tmp_dir)
        shutil.rmtree(tmp_dir)
        assert len(cache_files) <= THRESHOLD
项目:oa_qian    作者:sunqb    | 项目源码 | 文件源码
def test_filesystemcache_clear(self):
        tmp_dir = tempfile.mkdtemp()
        c = cache.FileSystemCache(cache_dir=tmp_dir)
        c.set('foo', 'bar')
        cache_files = os.listdir(tmp_dir)
        assert len(cache_files) == 1
        c.clear()
        cache_files = os.listdir(tmp_dir)
        assert len(cache_files) == 0
        shutil.rmtree(tmp_dir)
项目:wechat_spider    作者:CoolWell    | 项目源码 | 文件源码
def __init__(self, cache_dir='cache', default_timeout=300):
        """???

        cache_dir?????
        """
        self.cache = FileSystemCache(cache_dir, default_timeout=default_timeout)
项目:flask-sessionstore    作者:mcrowson    | 项目源码 | 文件源码
def __init__(self, cache_dir, threshold, mode, key_prefix,
                 use_signer=False, permanent=True):
        from werkzeug.contrib.cache import FileSystemCache
        self.cache = FileSystemCache(cache_dir, threshold=threshold, mode=mode)
        self.key_prefix = key_prefix
        self.use_signer = use_signer
        self.permanent = permanent
项目:edmunds    作者:LowieHuyghe    | 项目源码 | 文件源码
def test_file(self):
        """
        Test the file
        """

        # Write config
        self.write_config([
            "from edmunds.storage.drivers.file import File as StorageFile \n",
            "from edmunds.cache.drivers.file import File \n",
            "APP = { \n",
            "   'storage': { \n",
            "       'instances': [ \n",
            "           { \n",
            "               'name': 'file',\n",
            "               'driver': StorageFile,\n",
            "               'directory': '%s',\n" % self.storage_directory,
            "               'prefix': '%s',\n" % self.prefix,
            "           }, \n",
            "       ], \n",
            "   }, \n",
            "   'cache': { \n",
            "       'enabled': True, \n",
            "       'instances': [ \n",
            "           { \n",
            "               'name': 'file',\n",
            "               'driver': File,\n",
            "               'directory': '%s',\n" % self.cache_directory,
            "               'threshold': 500,\n",
            "               'default_timeout': 300,\n",
            "               'mode': 0o600,\n",
            "           }, \n",
            "           { \n",
            "               'name': 'file2',\n",
            "               'driver': File,\n",
            "               'directory': '/%s',\n" % self.cache_directory,
            "           }, \n",
            "       ], \n",
            "   }, \n",
            "} \n",
            ])

        # Create app
        app = self.create_application()

        driver = app.cache()
        self.assert_is_instance(driver, File)
        self.assert_is_instance(driver, FileSystemCache)

        self.clear_paths.append(driver._path)