-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from sitegeist/feature/cacheFusionObjectTreeIf…
…Enabled FEATURE: Fusion Object Tree Caching
- Loading branch information
Showing
6 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
namespace Sitegeist\Monocle\Aspects; | ||
|
||
/** | ||
* This file is part of the Sitegeist.Monocle package | ||
* | ||
* (c) 2016 | ||
* Martin Ficzel <[email protected]> | ||
* Wilhelm Behncke <[email protected]> | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Flow\Aop\JoinPointInterface; | ||
use Neos\Cache\Frontend\VariableFrontend; | ||
|
||
/** | ||
* @Flow\Scope("singleton") | ||
* @Flow\Aspect | ||
*/ | ||
class FusionCachingAspect | ||
{ | ||
/** | ||
* @Flow\Inject | ||
* @var VariableFrontend | ||
*/ | ||
protected $fusionCache; | ||
|
||
/** | ||
* @Flow\Around("setting(Sitegeist.Monocle.fusion.enableObjectTreeCache) && method(Sitegeist\Monocle\Fusion\FusionService->getMergedFusionObjectTreeForSitePackage())") | ||
* @param JoinPointInterface $joinPoint The current join point | ||
* @return mixed | ||
*/ | ||
public function cacheGetMergedFusionObjectTree(JoinPointInterface $joinPoint) | ||
{ | ||
$siteResourcesPackageKey = $joinPoint->getMethodArgument('siteResourcesPackageKey'); | ||
$cacheIdentifier = str_replace('.', '_', $siteResourcesPackageKey); | ||
|
||
if ($this->fusionCache->has($cacheIdentifier)) { | ||
$fusionObjectTree = $this->fusionCache->get($cacheIdentifier); | ||
} else { | ||
$fusionObjectTree = $joinPoint->getAdviceChain()->proceed($joinPoint); | ||
$this->fusionCache->set($cacheIdentifier, $fusionObjectTree); | ||
} | ||
|
||
return $fusionObjectTree; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
namespace Sitegeist\Monocle; | ||
|
||
/** | ||
* This file is part of the Sitegeist.Monocle package | ||
* | ||
* (c) 2016 | ||
* Martin Ficzel <[email protected]> | ||
* Wilhelm Behncke <[email protected]> | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Neos\Flow\Cache\CacheManager; | ||
use Neos\Flow\Core\Booting\Sequence; | ||
use Neos\Flow\Core\Bootstrap; | ||
use Neos\Flow\Monitor\FileMonitor; | ||
use Neos\Flow\Package\FlowPackageInterface; | ||
use Neos\Flow\Package\Package as BasePackage; | ||
use Neos\Flow\Package\PackageManager; | ||
use Neos\Flow\Package\PackageManagerInterface; | ||
|
||
/** | ||
* The Fluid Package | ||
* | ||
*/ | ||
class Package extends BasePackage | ||
{ | ||
|
||
/** | ||
* Invokes custom PHP code directly after the package manager has been initialized. | ||
* | ||
* @param Bootstrap $bootstrap The current bootstrap | ||
* @return void | ||
*/ | ||
public function boot(Bootstrap $bootstrap) | ||
{ | ||
$dispatcher = $bootstrap->getSignalSlotDispatcher(); | ||
|
||
$context = $bootstrap->getContext(); | ||
if (!$context->isProduction()) { | ||
$dispatcher->connect(Sequence::class, 'afterInvokeStep', function ($step) use ($bootstrap, $dispatcher) { | ||
if ($step->getIdentifier() === 'neos.flow:systemfilemonitor') { | ||
$templateFileMonitor = FileMonitor::createFileMonitorAtBoot('Sitegeist_Monocle_Fusion_Files', $bootstrap); | ||
$packageManager = $bootstrap->getEarlyInstance(PackageManagerInterface::class); | ||
/** | ||
* @var PackageManager $packageKey | ||
* @var FlowPackageInterface $package | ||
*/ | ||
foreach ($packageManager->getFlowPackages() as $packageKey => $package) { | ||
$templatesPath = $package->getResourcesPath() . 'Private/Fusion'; | ||
if (is_dir($templatesPath)) { | ||
$templateFileMonitor->monitorDirectory($templatesPath); | ||
} | ||
} | ||
|
||
$templateFileMonitor->detectChanges(); | ||
$templateFileMonitor->shutdownObject(); | ||
} | ||
}); | ||
} | ||
|
||
$flushTemplates = function ($identifier, $changedFiles) use ($bootstrap) { | ||
if ($identifier !== 'Sitegeist_Monocle_Fusion_Files') { | ||
return; | ||
} | ||
|
||
if ($changedFiles === []) { | ||
return; | ||
} | ||
|
||
$templateCache = $bootstrap->getObjectManager()->get(CacheManager::class)->getCache('Sitegeist_Monocle_Fusion'); | ||
$templateCache->flush(); | ||
}; | ||
$dispatcher->connect(FileMonitor::class, 'filesHaveChanged', $flushTemplates); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Sitegeist_Monocle_Fusion: | ||
frontend: Neos\Cache\Frontend\VariableFrontend | ||
backend: Neos\Cache\Backend\FileBackend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
|
||
Sitegeist: | ||
Monocle: | ||
fusion: | ||
enableObjectTreeCache: true | ||
|
||
packages: { } | ||
|
||
ui: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters