8

データを Symfony のファイル キャッシュに保存したいと考えています。read() および write() メソッドを使用してアプリ/キャッシュ キャッシュと対話する良い方法はありますか?

編集

優れたwinzou CacheBundleはまさに私が必要としていたものでした。

4

3 に答える 3

8

コントローラーから実行できます:

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);
于 2012-11-16T04:49:03.793 に答える
3

Note that DoctrineCacheBundle is now recommended. Don't be misled by the Doctrine branding - this is distinct and separate from the ORM and DBAL etc.

于 2015-02-22T22:28:39.923 に答える
0

何を達成しようとしているのかはよくわかりませんが、構成コンポーネントのドキュメント、特に ConfigCache クラスを見てください。

http://symfony.com/doc/current/components/config/index.html

http://symfony.com/doc/current/components/config/caching.html

于 2012-11-15T23:43:38.293 に答える