<p>Sounds like a custom <a href="https://craftcms.com/docs/3.x/extend/plugin-guide.html" rel="nofollow noreferrer">plugin</a> or <a href="https://craftcms.com/docs/3.x/extend/module-guide.html" rel="nofollow noreferrer">module</a> would work for you here, allowing you to hook into the entry after save event.</p>
<pre class="lang-php prettyprint-override"><code>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-&gt;sender;

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

    }
);
</code></pre>

CC BY-SA 4.0
2021-04-30T15:15:36.800Z
Perfect, this is just what I was after.  Thank you!
Tao
CC BY-SA 4.0
2021-04-27T21:23:57.193Z
2021-04-27T21:23:57.193Z
Matt Banner
<p>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.</p>
<p>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.</p>
<p>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.</p>
<p>Thanks for your time.</p>

<plugins><cache><headless>
Additional code to run when cache is busted(entry added/updated, etc)
# Additional code to run when cache is busted(entry added/updated, etc)

(Asked by: username_0 on 2021-04-27)

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.

**Tags:** plugins, cache, headless

---

## 1 answers

### Answer by username_1 on 2021-04-27. Score: 1 | Accepted answer

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.
        }

    }
);

> **Comments:**
> **username_0**: Perfect, this is just what I was after.  Thank you!  

---

