Skip to content

Instantly share code, notes, and snippets.

@a-am
Forked from daltonrooney/module.php
Created June 24, 2022 04:16
Show Gist options
  • Save a-am/e0df23203792bf584038459c696f8855 to your computer and use it in GitHub Desktop.
Save a-am/e0df23203792bf584038459c696f8855 to your computer and use it in GitHub Desktop.
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