1

I'm using Craft Pro 3.6 in Headless mode. I've found that caching the GraphQL responses on the frontend server dramatically speeds up our load time, even with enableGraphQlCaching turned on.

What I'd like to do is have Craft make a cUrl request to an endpoint on our frontend server whenever an entry is published or updated(or whenever the cache busting script would normally run) to clear the frontend cache.

I'm guessing the best approach would be a custom plugin? However, if there's an easier way to do this I'm all ears.

Thanks for your time.

1

Sounds like a custom plugin or module would work for you here, allowing you to hook into the entry after save event.

use craft\elements\Entry;
use craft\events\ModelEvent;
use yii\base\Event;

Event::on(
    Entry::class,
    Entry::EVENT_AFTER_SAVE,
    function(ModelEvent $event) {
        $entry = $event->sender;

        if (!$entry->getIsDraft()) {
            // Make the request to clear caches on the frontend.
        }

    }
);
1
  • Perfect, this is just what I was after. Thank you!
    – Tao
    Apr 30 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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