我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用werkzeug.contrib.cache.FileSystemCache()。
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)
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
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)
def __init__(self, cache_dir='cache', default_timeout=300): """??? cache_dir????? """ self.cache = FileSystemCache(cache_dir, default_timeout=default_timeout)
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
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)