TransWikia.com

How can I disable Symfony 5 class cache for local debugging?

Stack Overflow Asked by TheosK on December 25, 2021

I’m working on a custom json api (no twig involved). During development, I need to keep making constant changes to the codebase, and every response gets cached for a few minutes or until I clrear the symfony cache.

I’m using a local nginx server, which should be properly configured since these are the headers I get:

Server: nginx/1.16.1
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/7.4.1
Cache-Control: max-age=0, private
Date: Fri, 24 Jul 2020 07:29:28 GMT
X-Debug-Token: f38aeb
X-Debug-Token-Link: http://localhost:8080/_profiler/f38aeb
X-Robots-Tag: noindex
Last-Modified: Friday, 24-Jul-2020 07:29:28 UTC
Cache-Control: private no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0

and responses are properly updated once I run bin/console c:c

I need to do this every time I change any class (controllers, services, models, whatever).

There must be something obvious I’m missing. Is there a way to disable class caching on my dev environment and not having to clear the cache for every little change?

Edited: adding relevant configuration.

This is my nginx .conf file:

server {
    listen 80;
    server_name ~.*;

 location / {
     root /app;

     try_files $uri /index.php$is_args$args;
 }

 location ~ ^/index.php(/|$) {
     client_max_body_size 50m;

     fastcgi_pass php:9000;
     fastcgi_read_timeout 1800;
     fastcgi_buffers 16 16k;
     fastcgi_buffer_size 32k;
     include fastcgi_params;
     fastcgi_param SCRIPT_FILENAME /app/public/index.php;
     # Disable cache
     add_header Last-Modified $date_gmt;
     add_header Cache-Control 'private no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
     expires off;
     etag off;
 }

 error_log /dev/stderr debug;
 access_log /dev/stdout;
}

One Answer

I finally found the culprit. I'll leave this in case someone faces the same issue. I had opcache enabled in my dev environment, so it had nothing to do with symfony or the nginx location. I just disabled opcache and the issue was fixed.

opcache.enable=0

Answered by TheosK on December 25, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP