# Override the cache Directory

**URL:** <https://forum.shopware.com/t/override-the-cache-directory/40241>\
**Category:** Programmierung\
**Created:** [3. Oktober 2016 um 10:50 UTC](https://forum.shopware.com/t/override-the-cache-directory/40241 "2016-10-03T10:50:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sergey](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@Sergey](https://forum.shopware.com/u/Sergey)\
**Post date:** [3. Oktober 2016 um 10:50 UTC](https://forum.shopware.com/t/override-the-cache-directory/40241/1 "2016-10-03T10:50:25Z")

</div>

Hi guys.

I need to override path to&nbsp;the cache directory. This path locates in the&nbsp;Shopware\Kernel.php file

From what&nbsp;I could find, it is I can only extend Kernel and&nbsp;modify the&nbsp;shopware.php file&nbsp;but it is not a good solution.

Symfony 2/3 framework has&nbsp;AppKernel class where we can override the&nbsp;getCacheDir method.

> **[How to Override Symfony’s default Directory Structure (Symfony Docs)](https://symfony.com/doc/current/configuration/override_dir_structure.html)**
>
> How to Override Symfony’s default Directory Structure: Symfony applications have the following default directory structure, but you can override it to create your own structure: 1 2 3 4 5 6 7...

&nbsp;

My question is - how I can &nbsp;change a&nbsp;path to&nbsp;the cache directory without changing the&nbsp;shopware.php file?

---

<div class="post-metadata">

**Author:** ![Arya\_Svitkona](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/arya_svitkona/32/15319_2.png) [@Arya\_Svitkona](https://forum.shopware.com/u/Arya_Svitkona)\
**Post date:** [3. Oktober 2016 um 11:28 UTC](https://forum.shopware.com/t/override-the-cache-directory/40241/2 "2016-10-03T11:28:15Z")

</div>

May I ask you why you’d like to do that?  
I think that’s a bad idea at all, because for each SW Update you have to do the same steps over and over again 😉

---

<div class="post-metadata">

**Author:** ![Sergey](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@Sergey](https://forum.shopware.com/u/Sergey)\
**Post date:** [3. Oktober 2016 um 11:57 UTC](https://forum.shopware.com/t/override-the-cache-directory/40241/3 "2016-10-03T11:57:04Z")

</div>

This modification can be of interest if you are working in a virtual environment and cannot use NFS - for example, if you’re running a Symfony application using Vagrant/VirtualBox in a guest operating system.

---

<div class="post-metadata">

**Author:** ![shyim](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/shyim/32/7681_2.png) [@shyim](https://forum.shopware.com/u/shyim)\
**Post date:** [3. Oktober 2016 um 12:15 UTC](https://forum.shopware.com/t/override-the-cache-directory/40241/4 "2016-10-03T12:15:01Z")

</div>

You can override it in our config.php on root of our installation.&nbsp;

Look at:&nbsp;[shopware/Default.php at 5.2 · shopware/shopware · GitHub](https://github.com/shopware/shopware/blob/5.2/engine/Shopware/Configs/Default.php#L110)

---

<div class="post-metadata">

**Author:** ![Synonymous](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@Synonymous](https://forum.shopware.com/u/Synonymous)\
**Post date:** [3. Oktober 2016 um 12:34 UTC](https://forum.shopware.com/t/override-the-cache-directory/40241/5 "2016-10-03T12:34:39Z")

</div>

You can also simply define it in your config\_\*.php file:  
&nbsp;

```
'cache' => [
    'frontendOptions' => [
        'automatic_serialization' => true,
        'automatic_cleaning_factor' => 0,
        'lifetime' => 3600,
        'cache_id_prefix' => md5($this->getCacheDir())
    ],
    'backend' => 'auto', // e.G auto, apcu, xcache
    'backendOptions' => [
        'hashed_directory_perm' => 0777 & ~umask(),
        'cache_file_perm' => 0666 & ~umask(),
        'hashed_directory_level' => 3,
        'cache_dir' => $this->getCacheDir().'/general',
        'file_name_prefix' => 'shopware'
    ],
],

```

and for your HTTP Cache:

```
'httpcache' => [
        'enabled' => true,
        'lookup_optimization' => true,
        'debug' => false,
        'default_ttl' => 0,
        'private_headers' => ['Authorization', 'Cookie'],
        'allow_reload' => false,
        'allow_revalidate' => false,
        'stale_while_revalidate' => 2,
        'stale_if_error' => false,
        'cache_dir' => $this->getCacheDir().'/html',
        'cache_cookies' => ['shop', 'currency', 'x-cache-context-hash'],
    ],

```

&nbsp;
