Created
          May 12, 2020 22:32 
        
      - 
      
- 
        Save daltonrooney/e0f4e7217cc03fd8204a09e2db30209a to your computer and use it in GitHub Desktop. 
    Clear Craft CMS cache after Entry save event
  
        
  
    
      This file contains hidden or 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