vinnylinux
vinnylinux

Reputation: 7024

Storing Symfony 2 cache elsewere?

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?

Upvotes: 4

Views: 2417

Answers (2)

Jakub Zalas
Jakub Zalas

Reputation: 36191

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

Upvotes: 7

Matěj Koubík
Matěj Koubík

Reputation: 1147

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.

Upvotes: 0

Related Questions