gpt4 book ai didi

caching - 在 Symfony 2 中,是否有使用 read() 和 write() 方法与应用程序/缓存缓存交互的好方法?

转载 作者:行者123 更新时间:2023-12-04 06:42:07 25 4
gpt4 key购买 nike

我想将数据保存到 Symfony 的文件缓存中。是否有使用 read() 和 write() 方法与应用程序/缓存缓存交互的好方法?

编辑

winzou CacheBundle正是我所需要的。

最佳答案

您可以从 Controller 执行此操作:

use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Exception\IOException;

//Define your file path based on the cache one
$filename = $this->container->getParameter('kernel.cache_dir') . '/yourapp/filename.txt';

//Create your own folder in the cache directory
$fs = new Filesystem();
try {
$fs->mkdir(dirname($filename));
} catch (IOException $e) {
echo "An error occured while creating your directory";
}

//Write your file
file_put_contents($filename, 'Text content');

//Read the content of your file
echo file_get_contents($filename);

关于caching - 在 Symfony 2 中,是否有使用 read() 和 write() 方法与应用程序/缓存缓存交互的好方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13407790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com