Skip to content

Commit

Permalink
Merge branch 'release/1.0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Nov 27, 2017
2 parents 82cea12 + c7877d2 commit e307c1e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# FastCGI Cache Bust Changelog

## 1.0.3 - 2017.11.27
### Changed
* Don't bust the FastCGI Cache unless the element being saved is ENABLED or LIVE
* Don't bust the FastCGI Cache for certain custom ElementTypes

## 1.0.2 - 2017.08.12
### Changed
* Added 'FastCGI Cache' to the list of things that can be cleared via Craft's Clear Caches tool
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nystudio107/craft3-fastcgicachebust",
"description": "Bust the Nginx FastCGI Cache when entries are saved or created.",
"type": "craft-plugin",
"version": "1.0.2",
"version": "1.0.3",
"keywords": [
"craft",
"cms",
Expand Down
28 changes: 27 additions & 1 deletion src/FastcgiCacheBust.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
use nystudio107\fastcgicachebust\models\Settings;

use Craft;
use craft\base\Element;
use craft\base\Plugin;
use craft\elements\Entry;
use craft\events\ElementEvent;
use craft\events\RegisterCacheOptionsEvent;
use craft\services\Elements;
Expand Down Expand Up @@ -61,7 +63,31 @@ function (ElementEvent $event) {
'Elements::EVENT_AFTER_SAVE_ELEMENT',
__METHOD__
);
FastcgiCacheBust::$plugin->cache->clearAll();
/** @var Element $element */
$element = $event->element;
$isNewElement = $event->isNew;
$bustCache = true;
// Only bust the cache if the element is ENABLED or LIVE
if (($element->getStatus() != Element::STATUS_ENABLED)
&& ($element->getStatus() != Entry::STATUS_LIVE)
) {
$bustCache = false;
}
// Only bust the cache if it's not certain excluded element types
/* @TODO: These need to be updated once the plugins are released for Craft 3
if (($element instanceof 'SproutSeo_Redirect')
|| ($element instanceof 'PushNotifications_Device')
) {
$bustCache = false;
}
*/
if ($bustCache) {
Craft::trace(
"Cache busted due to saving: " . $element::className() . " - " . $element->title,
__METHOD__
);
FastcgiCacheBust::$plugin->cache->clearAll();
}
}
);

Expand Down

0 comments on commit e307c1e

Please sign in to comment.