-
-
Save a-am/e0df23203792bf584038459c696f8855 to your computer and use it in GitHub Desktop.
Clear Craft CMS cache after Entry save event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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