Skip to content

Commit

Permalink
Use site.ini/[ContentSettings]/CacheThreshold: if it is exceeded a gl…
Browse files Browse the repository at this point in the history
…obal expiry is used instead (mugoweb#18)
  • Loading branch information
Opencontent authored and pkamps committed Jul 1, 2018
1 parent dc6abe1 commit 5ca77b7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
29 changes: 24 additions & 5 deletions classes/StaticCacheMugoVarnish.php
Expand Up @@ -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' );
Expand Down Expand Up @@ -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);
}
}

Expand Down
4 changes: 4 additions & 0 deletions settings/mugo_varnish.ini
Expand Up @@ -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
Expand Down

0 comments on commit 5ca77b7

Please sign in to comment.