contao / manager-bundle

[READ-ONLY] Contao Manager Bundle
GNU Lesser General Public License v3.0
17 stars 10 forks source link

Use FOSHttpCacheBundle cache event listeners #46

Closed dmolineus closed 6 years ago

dmolineus commented 7 years ago

At the moment it isn't possible to refresh/invalidate the page cache for cache entries related to a page. Before 4.3 (?) it was possible to clear the cache by tracking the cache key using the getCacheKey hook.

For instance netzmacht/contao-cache-control and 1up-lab/contao-cache-warmup did it this way.

With https://github.com/contao/core-bundle/pull/576 the getCacheKey hook was removed from Contao.

To gain back more control of the default used HttpCache, i propose to add the (FOS HTTP Cache event listeners](http://foshttpcache.readthedocs.io/en/stable/symfony-cache-configuration.html#cache-event-listeners) by default and enable the bundle.

Providing a more flexible way to register own subscribers here would be great too. Adding the above mentioned listeners wouldn't need to be added by default. As the cache is created before the kernel is booting I don't know you it could be accomplished.

leofeyer commented 7 years ago

@contao/developers /cc

Toflar commented 7 years ago

Yeah I was already thinking about having a plugin that allows you to add your own subscribers. I guess @aschempp would be very thankful for a PR adding that to the manager plugin @dmolineus ;)

I don't think registering all subscribers by default makes sense but we should definitely add the PurgeListener!

dmolineus commented 7 years ago

If there is an agreement to add this feature I will provide an PR for it.

aschempp commented 7 years ago

I like the general idea, but I'm not sure how the concept would look in detail. I guess it would be best to discuss this in an upcoming Contao call.

dmolineus commented 7 years ago

Well, the basic idea is to provide an extra interface in the manager plugin. The HttpCache would use the plugin loader to initialize the event dispatcher.

I would prefer following:

namespace Contao\ManagerPlugin\Config;

class ContaoCachePluginInterface
{
   public function initialize(Contao\ManagerBundle\HttpKernel\ContaoCache $cache);
}

Or maybe if it better fits to the current implementation you could also provide following:

namespace Contao\ManagerPlugin\Config;

class ContaoCacheSubscriberPluginInterface
{
   /**
    * @return array
    */
   public function getSubscribers(array $subscribers);
}

class ContaoCacheListenerPluginInterface
{
   /**
    * @return array
    */
   public function getListeners(array $listeners);
}

Passing the available listeners/subscribers from other bundles could help extensions to avoid adding same listeners twice (then thinking of the FOSHttpCacheBundle listeners).

Toflar commented 7 years ago

What kind of listeners are you talking about if I may ask?

Toflar commented 6 years ago

I'll finish this as soon as Symfony 3.4 has been released as a first stable version. Before, HttpCache will not get a new stable tag because they're waiting too.

Toflar commented 6 years ago

Please assign this to milestone 4.6.0 😄

Toflar commented 6 years ago

Here we go https://github.com/contao/manager-bundle/pull/60 🎉 🎉 🎉