diff --git a/classes/StaticCacheMugoVarnish.php b/classes/StaticCacheMugoVarnish.php index 565d1a4..286e45d 100644 --- a/classes/StaticCacheMugoVarnish.php +++ b/classes/StaticCacheMugoVarnish.php @@ -15,11 +15,18 @@ class StaticCacheMugoVarnish implements ezpStaticCache static private $cleanUpHandlerRegistered = false; static protected $banConditions = array(); + + protected $useContentSettingsCacheThresholdValue; public function __construct() { $this->settings = eZINI::instance( 'mugo_varnish.ini' ); + if( $this->settings->hasVariable( 'VarnishSettings', 'UseCacheThresholdValue' ) ) + { + $this->useContentSettingsCacheThresholdValue = $this->settings->variable( 'VarnishSettings', 'UseCacheThresholdValue' ) == 'enabled'; + } + if( $this->settings->hasVariable( 'PurgeUrlBuilder', 'BuilderClass' ) ) { $builderClass = $this->settings->variable( 'PurgeUrlBuilder', 'BuilderClass' ); @@ -60,12 +67,24 @@ public function generateNodeListCache( $nodeList ) if( !empty( $nodeList ) ) { - foreach( $nodeList as $nodeId ) + $doClearNodeList = true; + if ($this->useContentSettingsCacheThresholdValue){ + $cleanupValue = eZContentCache::calculateCleanupValue( count( $nodeList ) ); + $doClearNodeList = eZContentCache::inCleanupThresholdRange( $cleanupValue ); + } + if ( $doClearNodeList ) + { + foreach( $nodeList as $nodeId ) + { + self::$banConditions = array_merge( + self::$banConditions, + $this->builder->buildConditionForNodeIdCache( $nodeId ) + ); + } + } + else { - self::$banConditions = array_merge( - self::$banConditions, - $this->builder->buildConditionForNodeIdCache( $nodeId ) - ); + $this->generateCache(true); } } diff --git a/settings/mugo_varnish.ini b/settings/mugo_varnish.ini index 7bdaf84..50457ff 100644 --- a/settings/mugo_varnish.ini +++ b/settings/mugo_varnish.ini @@ -22,6 +22,10 @@ ConnectionTimeout=1 # Maximal ban requests MaxBanRequests=1000 + +# Use site.ini/[ContentSettings]/CacheThreshold: if it is exceeded a global expiry is used instead +UseCacheThresholdValue=disabled + UseCurlMultiHandler=enabled # Enable to write every purge to the log file mugo_varnish_purges.log