diff --git a/CHANGELOG.md b/CHANGELOG.md index dd094ed19..09b672ef0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ## 07/xx/2017 1. [](#new) - * Added a new `cache-control` system and page level property [#1591](https://github.com/getgrav/grav/issues/1591) + * Added a new `cache_control` system and page level property [#1591](https://github.com/getgrav/grav/issues/1591) + * Added a new `clear_images_by_default` system property to stop cache clear events from removing processed images [#1481](https://github.com/getgrav/grav/pull/1481) # v1.3.1 ## 07/19/2017 diff --git a/system/blueprints/config/system.yaml b/system/blueprints/config/system.yaml index 4021255f3..4e806127c 100644 --- a/system/blueprints/config/system.yaml +++ b/system/blueprints/config/system.yaml @@ -514,6 +514,17 @@ form: help: PLUGIN_ADMIN.CACHE_PREFIX_HELP placeholder: PLUGIN_ADMIN.CACHE_PREFIX_PLACEHOLDER + cache.clear_images_by_default: + type: toggle + label: PLUGIN_ADMIN.CLEAR_IMAGES_BY_DEFAULT + help: PLUGIN_ADMIN.CLEAR_IMAGES_BY_DEFAULT_HELP + highlight: 1 + options: + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO + validate: + type: bool + cache.cli_compatibility: type: toggle label: PLUGIN_ADMIN.CLI_COMPATIBILITY diff --git a/system/config/system.yaml b/system/config/system.yaml index 9f25ff9b6..382c496be 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -74,6 +74,7 @@ cache: method: file # Method to check for updates in pages: file|folder|hash|none driver: auto # One of: auto|file|apc|xcache|memcache|wincache prefix: 'g' # Cache prefix string (prevents cache conflicts) + clear_images_by_default: true # By default grav will include processed images in cache clear, this can be disabled cli_compatibility: false # Ensures only non-volatile drivers are used (file, redis, memcache, etc.) lifetime: 604800 # Lifetime of cached data in seconds (0 = infinite) gzip: false # GZip compress the page output diff --git a/system/src/Grav/Common/Cache.php b/system/src/Grav/Common/Cache.php index 9baf42995..6746ab359 100644 --- a/system/src/Grav/Common/Cache.php +++ b/system/src/Grav/Common/Cache.php @@ -63,6 +63,14 @@ class Cache extends Getters 'asset://', ]; + protected static $standard_remove_no_images = [ + 'cache://twig/', + 'cache://doctrine/', + 'cache://compiled/', + 'cache://validated-', + 'asset://', + ]; + protected static $all_remove = [ 'cache://', 'cache://images', @@ -360,7 +368,12 @@ class Cache extends Getters $remove_paths = self::$tmp_remove; break; default: - $remove_paths = self::$standard_remove; + if (Grav::instance()['config']->get('system.cache.clear_images_by_default')) { + $remove_paths = self::$standard_remove; + } else { + $remove_paths = self::$standard_remove_no_images; + } + } // Clearing cache event to add paths to clear