FriendsOfSymfony / FOSJsRoutingBundle

A pretty nice way to expose your Symfony routing to client applications.
1.48k stars 261 forks source link

Bypass cache for exposed routes in debug mode #362

Closed nesk closed 4 years ago

nesk commented 4 years ago

I'm having a hard time with this package in local environments, I've included the JS script like this:

<script src="{{ asset('bundles/fosjsrouting/js/router.min.js') }}"></script>
<script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script>

However, whenever I add, change or remove a route in config/packages/fos_js_routing.yaml, I must run rm -rf var/cache/*/fosJsRouting (bin/console cache:clear doesn't work) to see the applied changes in the response of fos_js_routing_js.

It seems like ConfigCache is the culprit, so I've made a simple change to bypass the cache when the debug mode is enabled.

stof commented 4 years ago

the right solution instead would be to add a cache resource invalidating the cache when changing the exposed routes too.

nesk commented 4 years ago

@stof Couldn't agree more, but until someone is willing to do this (seems to require a bit of work) maybe we could merge this to solve the current issue?

tobias-93 commented 4 years ago

Thanks @nesk, I see no harm in ignoring the cache in debug mode so I've merged this.

timwsuqld commented 4 years ago

Further to my bug report in #389, looking at the code, ConfigCache should already be working correctly. @nesk did you look in the var/cache/dev/fosJsRouting/data.json.meta file to check if it was seeing config/packages/fos_js_routing.yaml file as a Resource? For example, I can see /srv/www/config/routes/0-fos_js_routing.yaml is listed in my meta file, which correctly reflects our routing files.