Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Add an option to disable nodes caching
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Jan 4, 2017
1 parent b8ff26a commit 0bec0a7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
10 changes: 1 addition & 9 deletions core/src/plugins/core.cache/AbstractCacheDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,7 @@ public function deleteKeyStartingWith($namespace, $id){
Logger::debug("CacheDriver::Http", "Clear Pattern ".$id, ["namespace" => $namespace]);
return $cacheDriver->deleteKeysStartingWith($id);
}


/**
* @return array
*/
public function listNamespaces(){
return [AJXP_CACHE_SERVICE_NS_SHARED, AJXP_CACHE_SERVICE_NS_NODES];
}


/**
* @param $namespace
* @return array|null
Expand Down
43 changes: 29 additions & 14 deletions core/src/plugins/core.cache/CoreCacheLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,34 @@ public function getImplementation($pluginsService = null)
$pluginInstance = ConfService::instanciatePluginFromGlobalParams($this->pluginConf["UNIQUE_INSTANCE_CONFIG"], "Pydio\\Cache\\Core\\AbstractCacheDriver", $pluginsService);
}
self::$cacheInstance = $pluginInstance;
if(!ApplicationState::sapiIsCli() && $pluginInstance !== null && $pluginInstance instanceof AbstractCacheDriver && $pluginInstance->supportsPatternDelete(AJXP_CACHE_SERVICE_NS_NODES)){
if(!ApplicationState::sapiIsCli() && !$this->pluginConf["CORE_CACHE_DISABLE_NODES"]
&& $pluginInstance !== null && $pluginInstance instanceof AbstractCacheDriver && $pluginInstance->supportsPatternDelete(AJXP_CACHE_SERVICE_NS_NODES)){
MetaStreamWrapper::appendMetaWrapper("pydio.cache", "\\Pydio\\Cache\\Core\\CacheStreamLayer");
}
}

return self::$cacheInstance;
}

/**
* Check if nodes caching is enabled
* @return bool
*/
public function enableNodesCaching(){
if($this->getConfigs()["CORE_CACHE_DISABLE_NODES"]) {
return false;
}
$cDriver = ConfService::getCacheDriverImpl();
return !(empty($cDriver) || !($cDriver->supportsPatternDelete(AJXP_CACHE_SERVICE_NS_NODES)));
}

/**
* @param \Pydio\Access\Core\Model\AJXP_Node $node
* @param \Pydio\Access\Core\Model\AJXP_Node $contextNode
* @param bool $details
*/
public function cacheNodeInfo(&$node, $contextNode, $details){
$cDriver = ConfService::getCacheDriverImpl();
if(empty($cDriver) || !($cDriver->supportsPatternDelete(AJXP_CACHE_SERVICE_NS_NODES))){
return;
}
if(!$this->enableNodesCaching()) return;
$id = $this->computeId($node, $details);
CacheService::save(AJXP_CACHE_SERVICE_NS_NODES, $id, $node->getNodeInfoMeta());
}
Expand All @@ -103,10 +113,7 @@ public function loadNodeInfoFromCache(&$node, $contextNode, $details, $forceRefr
Controller::applyHook("node.clear_cache_deferred", [&$node]);
return;
}
$cDriver = ConfService::getCacheDriverImpl();
if(empty($cDriver) || !($cDriver->supportsPatternDelete(AJXP_CACHE_SERVICE_NS_NODES))){
return;
}
if(!$this->enableNodesCaching()) return;
$id = $this->computeId($node, $details);
if(CacheService::contains(AJXP_CACHE_SERVICE_NS_NODES, $id)){
$metadata = CacheService::fetch(AJXP_CACHE_SERVICE_NS_NODES, $id);
Expand All @@ -123,10 +130,7 @@ public function loadNodeInfoFromCache(&$node, $contextNode, $details, $forceRefr
* @param bool $copy
*/
public function clearNodeInfoCache($from=null, $to=null, $copy = false){
$cDriver = ConfService::getCacheDriverImpl();
if(empty($cDriver) || !($cDriver->supportsPatternDelete(AJXP_CACHE_SERVICE_NS_NODES))){
return;
}
if(!$this->enableNodesCaching()) return;
if($from !== null){
$this->clearCacheForNode($from);
}
Expand Down Expand Up @@ -207,6 +211,17 @@ protected function computeId($node, $details){
return AbstractCacheDriver::getOptionsForNode($node, "node.info", $details?"all":"short")["id"];
}

/**
* @return array
*/
public function listNamespaces(){
if($this->enableNodesCaching()){
return [AJXP_CACHE_SERVICE_NS_SHARED, AJXP_CACHE_SERVICE_NS_NODES];
}else{
return [AJXP_CACHE_SERVICE_NS_SHARED];
}
}

/**
* @param ServerRequestInterface $requestInterface
* @param ResponseInterface $responseInterface
Expand All @@ -216,7 +231,7 @@ public function exposeCacheStats(ServerRequestInterface $requestInterface, Respo
$cImpl = $this->getImplementation();
$result = [];
if($cImpl != null){
$nspaces = $cImpl->listNamespaces();
$nspaces = $this->listNamespaces();
foreach ($nspaces as $nspace){
$data = $cImpl->getStats($nspace);
$data["namespace"] = $nspace;
Expand Down
5 changes: 4 additions & 1 deletion core/src/plugins/core.cache/manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
</resources>
</client_settings>
<server_settings>
<global_param type="plugin_instance:cache" name="UNIQUE_INSTANCE_CONFIG" group="CONF_MESSAGE[Cache Store Instance]" default="cache.doctrine" label="CONF_MESSAGE[Instance]" description="CONF_MESSAGE[Choose the configuration plugin]" mandatory="false"/>
<global_param type="plugin_instance:cache" name="UNIQUE_INSTANCE_CONFIG" group="CONF_MESSAGE[Cache Store Instance]"
default="cache.doctrine" label="CONF_MESSAGE[Instance]" description="CONF_MESSAGE[Choose the configuration plugin]" mandatory="false"/>
<global_param group="CONF_MESSAGE[Cache Store Instance]" name="CORE_CACHE_DISABLE_NODES" type="boolean" label="CONF_MESSAGE[Disable Nodes Caching]"
description="CONF_MESSAGE[Cache files and folders data in memory. Depending on the amount of data and on the caching method used (remote cache), this can be disabled.]" default="false"/>
</server_settings>
<registry_contributions>
<actions>
Expand Down

0 comments on commit 0bec0a7

Please sign in to comment.