I'm creating some REST routes for my custom resources and I'm having some trouble with the debugging aspect of development.

Every time I change the resource's code, should I need to XDebug it, I need to clear Drupal's cache (drush cr) for the debug to work.

I have successfully disabled the ResourceResponse cache mechanism, so that when the data has changed in Drupal, it is reflected on the response.

Although, I think that maybe due to the annotation mechanism, it's caching the function of my REST Resource, and, subsequently, when I change it, those changes don't propagate and Xdebug doesn't pick them up.

I also noticed that git signals that the resource plugin file has changed every time I clear the cache, which I think might be related.

Does anyone have some pointers they can share to overcome this?

  • 1
    you didn't mention if you followed these steps to disable caching for development drupal.org/node/2598914
    – 4uk4
    Mar 20, 2017 at 10:06
  • @4k4 your are right, I was unaware of this procedure. Although, I have all caching disabled via Drupal's Config/Performance option. Does this go deeper than that? I'll try it out either way.
    – Joum
    Mar 20, 2017 at 10:49
  • yes, for what you are doing now with XDebug you need this, later switch it off again to test how the site works with caching
    – 4uk4
    Mar 20, 2017 at 10:57
  • @4k4 I followed the procedure as explained in the link above, but it's still working the same way. Any other ideas?
    – Joum
    Mar 20, 2017 at 11:13
  • 1
    would be great if you put what you found out in an answer
    – 4uk4
    Mar 20, 2017 at 11:41

1 Answer 1


As per @4k4 's suggestion, I'll try to put into and answer what he helped me figure out (though some details are still a bit murky).

When developing in a local environment, we can override the settings.php file with a settings.local.php file. In this local file, we can setup several settings regarding disabling Drupal's cache functionality.

At the time of writing, the instructions in this link were pretty straightforward and sufficient, but I would like to point out a few aspects that I felt weren't very explicit:

  • In my specific case, while developing custom REST Resources, both the response and the function of my resource were being cached. This is something I want to work like this in production. Although, for development, caching the function of my REST Resource meant that everytime I changed it, I had to clear the cache to allow for XDebug to see the changes in my Resource file. I overcame this by following the instructions in the Find cache bins section of the above link. Regarding my use case, I think the relevant cache bins should be the discovery and rest.
  • I think (though not sure), that having these bins not cached results in having to clear the cache if you add new discoverable code to your installation, ie, modules, REST resources, maybe themes. As these operations aren't as frequent in my case as the debugging procedure, it's a tradeoff I'm willing to make, but YMMV.
  • If you are using gitto version your code base, be sure to .gitignore the sites/default/settings.local.php file, otherwise it might end up in your production server, making it substantially slower.
  • I also tried following the procedure using Drupal Console as the link above suggested, but apparently since version 1.0.0-rc12 the drupal site:mode dev command isn't supported because it proved unstable. Maybe that will change soon.
  • great answer, you should also include the render cache bin, which stores all kind of responses, not only HTML
    – 4uk4
    Mar 20, 2017 at 12:23
  • I would expect that disabling the two cache bins that are already listed in example.settings.local.php (api.drupal.org/api/drupal/sites%21example.settings.local.php/…) should be enough: render and dynamic_page_cache. discovery and rest are about caching the definition of your plugin, relationships and so on, something that you most likely don't change once it is set up and working.
    – Berdir
    Mar 20, 2017 at 21:04
  • 1
    "I think (though not sure), that having these bins not cached results in having to clear the cache". No, if you disable a bin by using the null backend then it's always less things being cached, not more. Also, all those caches usually invalidate themself automatically if you install a module, only if you add files to an installed module then you need to do it manually
    – Berdir
    Mar 20, 2017 at 21:05
  • @Berdir I have no idea why, but just uncommenting the render and dynamic page cache settings in the local file did nothing for my custom REST Resources cache. Both the function and the responses were being cached and Xdebug didn't pick up the changes, which was my main concern.
    – Joum
    Mar 21, 2017 at 10:17
  • @4k4 I ended up adding the render bin as well. When I awk'ed the bins as per the tutorial, it also listed the render bin, so I also added it to the cache.backend.null setting.
    – Joum
    Mar 21, 2017 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.