Skip to content

Instantly share code, notes, and snippets.

@daltonrooney
Created May 12, 2020 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save daltonrooney/e0f4e7217cc03fd8204a09e2db30209a to your computer and use it in GitHub Desktop.
Save daltonrooney/e0f4e7217cc03fd8204a09e2db30209a 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