Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Clear Craft CMS cache after Entry save event
<?php
use yii\base\Event;
use Craft;
use craft\elements\Entry;
Event::on(
Entry::class,
Entry::EVENT_AFTER_SAVE,
function(ModelEvent $event) {
$entry = $event->sender;
//Only flush cache when certain sections are saved
if ( $entry->sectionId == 2 || $entry->sectionId == 8 ) {
Craft::$app->getCache()->flush();
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment