ostark / upper

Integrates Edge Caches like Fastly, KeyCDN, Cloudflare and Varnish with Craft.
MIT License
102 stars 22 forks source link

Support for multiple Cloudflare domains #32

Closed bwlng closed 4 years ago

bwlng commented 5 years ago

Is it possible to clear the cache for multiple Cloudflare zones/domains? I’m using Upper on a Craft install where each site has a different domain. Is there a way to configure multiple zoneIds or domains (such as an array with nested config options under cloudflare in config/upper.php or arrays for zoneId and domain)?

ostark commented 5 years ago

Hi Stephen,

this is not possible, however, there is PurgeEvent, which is not fired so far - I never had a real use case.

Something like this (once implemented) could work :

\Event::on(
    \ostark\upper\Plugin::class,
    \ostark\upper\Plugin::EVENT_BEFORE_PURGE,
    function (\ostark\upper\events\PurgeEvent $event) {
        $site = \Craft::$app->getSites()->getSiteById($event->element->siteId);
        $purger = Plugin::getInstance()->getPurger();
        $purger->domain = $site->baseUrl;
      }
);

Do you want to provide a PR? Or is this requirement not so important ;-)?

bwlng commented 5 years ago

Hi Oliver,

Thanks for that info. I will look into a PR and see how far I can take it 😉

Would you prefer Upper to fire the PurgeEvent and then folks with use cases like mine would listen for the event in their own module?

ostark commented 5 years ago

there is no Module required, you can listen directly from you config/app.php using a closure

ostark commented 5 years ago

@bwlng Is this still a requirement?

bwlng commented 5 years ago

@ostark Yes, I haven’t had a chance to provide a PR, but hope to do so.