How to disable cache in symfony

How to disable cache in symfony

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Disabling Cache in Symfony: A Strategic Approach

When a developer discovers that the var/cache directory has ballooned to an unexpected size, it often signals that automatic cache warming or invalidation logic is behaving differently than anticipated in the current environment. While Symfony's caching system is designed for performance, blindly deleting files or assuming there is a single "disable" switch can lead to runtime errors if the application expects cached data to exist.

To truly disable caching permanently, you must distinguish between the infrastructure that stores data and the configuration that populates it. The most direct method involves modifying the .env file to ensure no cache pools are active by default. In a standard Symfony installation, this is controlled via the APP_DEBUG environment variable or specific cache pool definitions in your config/packages/cache.yaml.

If you are running on a local development machine where performance gains from caching are negligible and debugging requires fresh data every time, set APP_DEBUG=1 in your .env file. While this primarily enables debug mode, it also configures the default cache pool to use the filesystem driver but prevents the automatic creation of the cache directory if it doesn't exist during the bootstrap phase. However, relying solely on debug mode is not a robust strategy for permanent cache disabling in production-like scenarios because Symfony still attempts to write to the cache folder unless explicitly told otherwise.

The definitive way to disable caching is to remove the cache pool configuration entirely or configure all pools to be non-active. Open your config/packages/cache.yaml file. By default, this file might look like this:

framework:
    cache:
        # default_app_cache_pool is active by default
        # default_system_cache_pool is active by default
        app: cache.adapter.filesystem
        system: cache.adapter.filesystem

To disable the application cache pool, you can comment out the app entry or, more strictly, ensure that no pools are registered in the container. A common and cleaner approach for development environments where you want to guarantee zero caching overhead is to define the pools but set their lifespan to 0 seconds, effectively making them useless:

framework:
    cache:
        app:
            prefix: ''
            pool: '%kernel.debug%' # Only active in debug mode
        system:
            prefix: ''
            pool: '%kernel.debug%'

However, if your goal is to prevent the application from attempting to write to the cache directory at all, you should physically remove or rename the var/cache directory. Symfony will recreate it on the first request when a session starts or when the kernel boots, but only if the configuration allows it. If you want to force Symfony to skip cache creation entirely, you can set the APP_CACHE_DIR environment variable to an empty string or point it to a path that does not exist and refuse to create it via code logic, though this is rarely necessary.

A more critical consideration involves third-party bundles like Twig or Doctrine. Even if you clear the main cache folder, these bundles may have their own dedicated storage locations. For example, Doctrine ORM often caches metadata in var/cache/doctrine or similar subdirectories depending on your configuration. Disabling the framework-level cache does not automatically disable entity hydration caching or query result caching if those are configured separately. You must inspect your doctrine.yaml file for any metadata_cache_driver settings and switch them to array or ensure they point to a location you intend to manage manually.

Similarly, Twig templates might be cached in the same directory, but their configuration is usually tied to the main cache pool. If you disable the main pool, Twig stops caching compiled templates. However, always verify that your specific version of Symfony and the bundles you are using do not introduce fallback caching mechanisms.

Finally, consider the trade-off between developer convenience and application performance. Disabling cache permanently is excellent for debugging complex state issues or when testing edge cases where stale data could mask bugs. But remember that in a production environment, disabling cache can degrade performance significantly, leading to increased memory usage and slower response times as every request forces the application to recompute logic or fetch fresh data from the database.

If you require a robust solution for managing cache lifecycles without manual deletions, look into cache warming tools or integrate with your deployment pipeline to clear caches automatically after code changes. For teams migrating between frameworks or seeking similar capabilities in other PHP ecosystems, resources like https://laravelcompany.com often provide insights into how caching strategies differ across popular frameworks, highlighting the importance of understanding the specific cache drivers available.

Our network