├── resources ├── js │ └── FastcgiCacheBust_Script.js ├── css │ └── FastcgiCacheBust_Style.css └── icon.svg ├── composer.json ├── translations └── en.php ├── .craftplugin ├── config.php ├── CHANGELOG.md ├── templates └── FastcgiCacheBust_Settings.twig ├── LICENSE.txt ├── services └── FastcgiCacheBustService.php ├── releases.json ├── README.md └── FastcgiCacheBustPlugin.php /resources/js/FastcgiCacheBust_Script.js: -------------------------------------------------------------------------------- 1 | /** 2 | * FastCGI Cache Bust plugin for Craft CMS 3 | * 4 | * FastCGI Cache Bust JS 5 | * 6 | * @author nystudio107 7 | * @copyright Copyright (c) 2017 nystudio107 8 | * @link https://nystudio107.com 9 | * @package FastcgiCacheBust 10 | * @since 1.0.0 11 | */ 12 | -------------------------------------------------------------------------------- /resources/css/FastcgiCacheBust_Style.css: -------------------------------------------------------------------------------- 1 | /** 2 | * FastCGI Cache Bust plugin for Craft CMS 3 | * 4 | * FastCGI Cache Bust CSS 5 | * 6 | * @author nystudio107 7 | * @copyright Copyright (c) 2017 nystudio107 8 | * @link https://nystudio107.com 9 | * @package FastcgiCacheBust 10 | * @since 1.0.0 11 | */ 12 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nystudio107/fastcgicachebust", 3 | "description": "Bust the Nginx FastCGI Cache when entries are saved or created.", 4 | "type": "craft-plugin", 5 | "authors": [ 6 | { 7 | "name": "nystudio107", 8 | "homepage": "https://nystudio107.com" 9 | } 10 | ], 11 | "require": { 12 | "composer/installers": "~1.0" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /translations/en.php: -------------------------------------------------------------------------------- 1 | 'FastCGI Cache', 16 | ); 17 | -------------------------------------------------------------------------------- /.craftplugin: -------------------------------------------------------------------------------- 1 | {"pluginName":"FastCGI Cache Bust","pluginDescription":"Bust the Nginx FastCGI Cache when entries are saved or created.","pluginVersion":"1.0.0","pluginAuthorName":"nystudio107","pluginAuthorUrl":"https://nystudio107.com","pluginAuthorGithub":"nystudio107","codeComments":"","pluginComponents":["services","settings"],"controllerName":"","elementName":"","fieldName":"","modelName":"","purchasableName":"","recordName":"","serviceName":"","taskName":"","widgetName":"","apiVersion":"api_version_2_5"} -------------------------------------------------------------------------------- /config.php: -------------------------------------------------------------------------------- 1 | '', 16 | ); 17 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # FastCGI Cache Bust Changelog 2 | 3 | ## 1.0.4 -- 2017.12.10 4 | ### Added 5 | * You can have more than one cache to have it clear by separating the paths with a comma (`,`) in the config settings 6 | 7 | ## 1.0.3 -- 2017.11.27 8 | ### Added 9 | * Don't bust the FastCGI Cache unless the element being saved is ENABLED or LIVE 10 | * Don't bust the FastCGI Cache for certain custom ElementTypes 11 | 12 | ## 1.0.2 -- 2017.08.12 13 | ### Added 14 | * Added 'FastCGI Cache' to the list of things that can be cleared via Craft's Clear Caches tool 15 | 16 | ## 1.0.1 -- 2017.06.18 17 | ### Added 18 | * Added multi-environment config overrides via `fastcgicachebust.php` 19 | 20 | ## 1.0.0 -- 2017.06.15 21 | ### Added 22 | * Initial release 23 | 24 | Brought to you by [nystudio107](https://nystudio107.com) 25 | -------------------------------------------------------------------------------- /templates/FastcgiCacheBust_Settings.twig: -------------------------------------------------------------------------------- 1 | {# 2 | /** 3 | * FastCGI Cache Bust plugin for Craft CMS 4 | * 5 | * FastCGI Cache Bust Settings.twig 6 | * 7 | * @author nystudio107 8 | * @copyright Copyright (c) 2017 nystudio107 9 | * @link https://nystudio107.com 10 | * @package FastcgiCacheBust 11 | * @since 1.0.0 12 | */ 13 | #} 14 | 15 | {% import "_includes/forms" as forms %} 16 | 17 | {% includeCssResource "fastcgicachebust/css/FastcgiCacheBust_Style.css" %} 18 | {% includeJsResource "fastcgicachebust/js/FastcgiCacheBust_Script.js" %} 19 | 20 | {{ forms.textField({ 21 | label: 'FastCGI Cache Path', 22 | instructions: 'Enter the full absolute path to the FastCGI Cache directory. If you require more than one FastCGI Cache directory cleared, separate the paths with a comma (,).', 23 | id: 'cachePath', 24 | name: 'cachePath', 25 | value: settings['cachePath']}) 26 | }} 27 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2017 nystudio107 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /services/FastcgiCacheBustService.php: -------------------------------------------------------------------------------- 1 | plugins->getPlugin('fastcgicachebust')->getSettings(); 24 | if (!empty($settings)) { 25 | if (!empty($settings->cachePath)) { 26 | $cacheDirs = explode(',', $settings->cachePath); 27 | foreach ($cacheDirs as $cacheDir) { 28 | $cacheDir = trim($cacheDir); 29 | $result = IOHelper::clearFolder($cacheDir, false); 30 | Craft::log("FastCGI Cache busted: `".$cacheDir."` - ".$result, LogLevel::Info, false); 31 | } 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /releases.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "version": "1.0.4", 4 | "downloadUrl": "https://github.com/nystudio107/fastcgicachebust/archive/master.zip", 5 | "date": "2017-12-10T22:35:46.832Z", 6 | "notes": [ 7 | "[Added] You can have more than one cache to have it clear by separating the paths with a comma (`,`) in the config settings" 8 | ] 9 | }, 10 | { 11 | "version": "1.0.3", 12 | "downloadUrl": "https://github.com/nystudio107/fastcgicachebust/archive/master.zip", 13 | "date": "2017-11-27T22:35:46.832Z", 14 | "notes": [ 15 | "[Improved] Don't bust the FastCGI Cache unless the element being saved is ENABLED or LIVE", 16 | "[Improved] Don't bust the FastCGI Cache for certain custom ElementTypes" 17 | ] 18 | }, 19 | { 20 | "version": "1.0.2", 21 | "downloadUrl": "https://github.com/nystudio107/fastcgicachebust/archive/master.zip", 22 | "date": "2017-08-12T22:35:46.832Z", 23 | "notes": [ 24 | "[Added] Added 'FastCGI Cache' to the list of things that can be cleared via Craft's Clear Caches tool" 25 | ] 26 | }, 27 | { 28 | "version": "1.0.1", 29 | "downloadUrl": "https://github.com/nystudio107/fastcgicachebust/archive/master.zip", 30 | "date": "2017-06-18T22:35:46.832Z", 31 | "notes": [ 32 | "[Added] Added multi-environment config overrides via `fastcgicachebust.php`" 33 | ] 34 | }, 35 | { 36 | "version": "1.0.0", 37 | "downloadUrl": "https://github.com/nystudio107/fastcgicachebust/archive/master.zip", 38 | "date": "2017-06-15T22:35:46.832Z", 39 | "notes": [ 40 | "[Added] Initial release" 41 | ] 42 | } 43 | ] 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![No Maintenance Intended](http://unmaintained.tech/badge.svg)](http://unmaintained.tech/) 2 | 3 | # DEPRECATED 4 | 5 | This Craft CMS 2.x plugin is no longer supported, but it is fully functional, and you may continue to use it as you see fit. The license also allows you to fork it and make changes as needed for legacy support reasons. 6 | 7 | The Craft CMS 3.x version of this plugin can be found here: [craft-fastcgicachebust](https://github.com/nystudio107/craft-fastcgicachebust) and can also be installed via the Craft Plugin Store in the Craft CP. 8 | 9 | # FastCGI Cache Bust plugin for Craft CMS 10 | 11 | Bust the Nginx FastCGI Cache when entries are saved or created. 12 | 13 | Related: [FastCGI Cache Bust for Craft 3.x](https://github.com/nystudio107/craft3-fastcgicachebust) 14 | 15 | ## Installation 16 | 17 | To install FastCGI Cache Bust, follow these steps: 18 | 19 | 1. Download & unzip the file and place the `fastcgicachebust` directory into your `craft/plugins` directory 20 | 2. -OR- do a `git clone https://github.com/nystudio107/fastcgicachebust.git` directly into your `craft/plugins` folder. You can then update it with `git pull` 21 | 3. -OR- install with Composer via `composer require nystudio107/fastcgicachebust` 22 | 4. Install plugin in the Craft Control Panel under Settings > Plugins 23 | 5. The plugin folder should be named `fastcgicachebust` for Craft to see it. GitHub recently started appending `-master` (the branch name) to the name of the folder for zip file downloads. 24 | 25 | FastCGI Cache Bust works on Craft 2.5.x and Craft 2.6.x. 26 | 27 | ## FastCGI Cache Bust Overview 28 | 29 | FastCGI Cache Bust is a simple plugin that clears your entire FastCGI Cache any time an entry is saved. This is somewhat of a scortched earth approach to cache invalidation, but it ensure cache coherency. 30 | 31 | Check out the article [Static Page Caching with Craft CMS](https://nystudio107.com/blog/static-caching-with-craft-cms) for details on how to set up FastCGI Cache on your website. 32 | 33 | ## Configuring FastCGI Cache Bust 34 | 35 | Click on the gear icon next to the plugin to configure it by adding the full absolute path to your Nginx FastCGI Cache directory. If you require more than one FastCGI Cache directory cleared, separate the paths with a comma (`,`). 36 | 37 | ## Using FastCGI Cache Bust 38 | 39 | FastCGI Cache Bust listens for elements being saved, and busts the entire FastCGI Cache automatically when that happens. 40 | 41 | You can also manually clear the FastCGI Cache via Craft's 'Clear Caches' tool 42 | 43 | ## FastCGI Cache Bust Roadmap 44 | 45 | Some things to do, and ideas for potential features: 46 | 47 | * We could invalidate only affected caches onElementSave instead of the entire cache 48 | 49 | Brought to you by [nystudio107](https://nystudio107.com) 50 | -------------------------------------------------------------------------------- /FastcgiCacheBustPlugin.php: -------------------------------------------------------------------------------- 1 | on('elements.onSaveElement', function (Event $event) { 25 | /** @var BaseElementModel $element */ 26 | $element = $event->params['element']; 27 | $isNewElement = $event->params['isNewElement']; 28 | $bustCache = true; 29 | // Only bust the cache if the element is ENABLED or LIVE 30 | if (($element->getStatus() != BaseElementModel::ENABLED) && ($element->getStatus() != EntryModel::LIVE)) { 31 | $bustCache = false; 32 | } 33 | // Only bust the cache if it's not certain excluded element types 34 | $elemType = $element->getElementType(); 35 | if (($elemType == 'SproutSeo_Redirect') || ($elemType == 'PushNotifications_Device')) { 36 | $bustCache = false; 37 | } 38 | 39 | if ($bustCache) { 40 | FastcgiCacheBustPlugin::log( 41 | "Cache busted due to saving: " . $elemType . " - " . $element->getTitle(), 42 | LogLevel::Info, 43 | true 44 | ); 45 | craft()->fastcgiCacheBust->clearAll(); 46 | } 47 | }); 48 | } 49 | 50 | /** 51 | * @return mixed 52 | */ 53 | public function getName() 54 | { 55 | return Craft::t('FastCGI Cache Bust'); 56 | } 57 | 58 | /** 59 | * @return mixed 60 | */ 61 | public function getDescription() 62 | { 63 | return Craft::t('Bust the Nginx FastCGI Cache when entries are saved or created.'); 64 | } 65 | 66 | /** 67 | * @return string 68 | */ 69 | public function getDocumentationUrl() 70 | { 71 | return 'https://github.com/nystudio107/fastcgicachebust/blob/master/README.md'; 72 | } 73 | 74 | /** 75 | * @return string 76 | */ 77 | public function getReleaseFeedUrl() 78 | { 79 | return 'https://raw.githubusercontent.com/nystudio107/fastcgicachebust/master/releases.json'; 80 | } 81 | 82 | /** 83 | * @return string 84 | */ 85 | public function getVersion() 86 | { 87 | return '1.0.4'; 88 | } 89 | 90 | /** 91 | * @return string 92 | */ 93 | public function getSchemaVersion() 94 | { 95 | return '1.0.0'; 96 | } 97 | 98 | /** 99 | * @return string 100 | */ 101 | public function getDeveloper() 102 | { 103 | return 'nystudio107'; 104 | } 105 | 106 | /** 107 | * @return string 108 | */ 109 | public function getDeveloperUrl() 110 | { 111 | return 'https://nystudio107.com'; 112 | } 113 | 114 | /** 115 | * @return bool 116 | */ 117 | public function hasCpSection() 118 | { 119 | return false; 120 | } 121 | 122 | /** 123 | * @inheritdoc 124 | */ 125 | protected function defineSettings() 126 | { 127 | return array( 128 | 'cachePath' => array(AttributeType::String, 'label' => 'FastCGI Cache Path', 'default' => ''), 129 | ); 130 | } 131 | 132 | /** 133 | * @inheritdoc 134 | */ 135 | public function getSettings() 136 | { 137 | $settings = parent::getSettings(); 138 | $base = $this->defineSettings(); 139 | 140 | foreach ($base as $key => $row) { 141 | $override = craft()->config->get($key, 'fastcgicachebust'); 142 | 143 | if (!is_null($override) && !empty($override)) { 144 | $settings->$key = $override; 145 | } 146 | } 147 | 148 | return $settings; 149 | } 150 | 151 | /** 152 | * @inheritdoc 153 | */ 154 | public function getSettingsHtml() 155 | { 156 | return craft()->templates->render('fastcgicachebust/FastcgiCacheBust_Settings', [ 157 | 'settings' => $this->getSettings(), 158 | ]); 159 | } 160 | 161 | /** 162 | * @inheritdoc 163 | */ 164 | public function prepSettings($settings) 165 | { 166 | // Modify $settings here... 167 | 168 | return $settings; 169 | } 170 | 171 | /** 172 | * Adds the FastCGI Cache path to the list of things the Clear Caches tool can delete. 173 | * 174 | * @return array 175 | */ 176 | public function registerCachePaths() 177 | { 178 | $cachePaths = array(); 179 | $settings = $this->getSettings(); 180 | if (!empty($settings)) { 181 | if (!empty($settings->cachePath)) { 182 | $cacheDirs = explode(',', $settings->cachePath); 183 | foreach ($cacheDirs as $cacheDir) { 184 | $cacheDir = trim($cacheDir); 185 | $cachePaths = array_merge( 186 | $cachePaths, 187 | [ 188 | $cacheDir => Craft::t('FastCGI Cache'). ' '.$cacheDir, 189 | ] 190 | ); 191 | } 192 | } 193 | } 194 | 195 | return $cachePaths; 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /resources/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 59 | 62 | 64 | 67 | 69 | 71 | 74 | 76 | 81 | 84 | 86 | 90 | 93 | 95 | 98 | 100 | 101 | 102 | 106 | 107 | 108 | 109 | 110 | 116 | 117 | 120 | 122 | 125 | 127 | 128 | 129 | 131 | 132 | 133 | 135 | 136 | 138 | 139 | 140 | 141 | 142 | --------------------------------------------------------------------------------