Symfony의 파일 캐시에 데이터를 저장하고 싶습니다. read() 및 write() 메소드를 사용하여 app/cache 캐시와 상호 작용할 수있는 좋은 방법이 있습니까?Symfony 2에서 read() 및 write() 메소드를 사용하여 app/cache 캐시와 상호 작용할 수있는 좋은 방법이 있습니까?
편집
우수한 winzou CacheBundle 내가 필요 정확히이었다.
Symfony의 파일 캐시에 데이터를 저장하고 싶습니다. read() 및 write() 메소드를 사용하여 app/cache 캐시와 상호 작용할 수있는 좋은 방법이 있습니까?Symfony 2에서 read() 및 write() 메소드를 사용하여 app/cache 캐시와 상호 작용할 수있는 좋은 방법이 있습니까?
편집
우수한 winzou CacheBundle 내가 필요 정확히이었다.
당신이 할 수있는 컨트롤러에서 확인하십시오 :
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);
아니 ConfigCache 클래스에서 당신이 달성하기 위해 노력하고 있지만 구성 요소 설명서를 살펴 거라고, 특히 정말로 확인하십시오
http://symfony.com/doc/current/components/config/index.html
http://symfony.com/doc/current/components/config/caching.html
이제 DoctrineCacheBundle이 좋습니다. 에드. Doctrine 브랜딩에 오해하지 마세요. 이것은 ORM과 DBAL 등과 구분됩니다.
파일 시스템을 사용하는 경우 mkdir 대신 filefput()을 사용하여 $ fs-> dumpFile()을 수행 할 수 있습니다. 더 콤팩트하고 우아한. – dbu
대신 새로운 파일 시스템을 사용한다면 $ this-> get ('filesystem')을 사용하여 파일 시스템 서비스를 얻을 수 있습니다. – dbu