Storing Symfony 2 cache elsewere?

后端 未结 2 1707
小鲜肉
小鲜肉 2021-01-14 06:59

Is there a way to store symfony 2 cache (app/cache) somewhere else other than the filesystem? Memcache, S3, or something? Any built-in option?

相关标签:
2条回答
  • 2021-01-14 07:27

    You can only move it outside of the project directory by overloading getCacheDir() method in the AppKernel class.

    What's the point of moving it to Memcache? Contents of this directory is most of the time "compiled" classes and templates. Those files are put into memory anyway (APC does that).

    Edit: On development, it's harder to avoid I/O, but you can easily move Symfony's cache dir to memory by overriding AppKernel's getCacheDir() and getLogDir() methods to point them to /dev/shm:

    class AppKernel extends Kernel
    {
        // ...
    
        public function getCacheDir()
        {
            if (in_array($this->environment, array('dev', 'test'))) {
                return '/dev/shm/appname/cache/' .  $this->environment;
            }
    
            return parent::getCacheDir();
        }
    
        public function getLogDir()
        {
            if (in_array($this->environment, array('dev', 'test'))) {
                return '/dev/shm/appname/logs';
            }
    
            return parent::getLogDir();
        }
    }
    

    Source: http://www.whitewashing.de/2013/08/19/speedup_symfony2_on_vagrant_boxes.html

    0 讨论(0)
  • 2021-01-14 07:33

    You can use Gaufrette (https://github.com/KnpLabs/Gaufrette, https://github.com/KnpLabs/KnpGaufretteBundle) to create a virtual filesystem from almost any storage possible (APC, memory, S3, FTP, SQL db). Then set cache-dir to gaufrette://s3 for example.

    0 讨论(0)
提交回复
热议问题