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

Commit

Permalink
Initial commit: Uses doctrine cache drivers as main caching system
Browse files Browse the repository at this point in the history
  • Loading branch information
ghecquet committed Jan 29, 2016
1 parent f64e1ef commit 6a88906
Show file tree
Hide file tree
Showing 100 changed files with 6,911 additions and 80 deletions.
18 changes: 18 additions & 0 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions core/src/cmd.php
Expand Up @@ -33,13 +33,9 @@
//set_error_handler(array("AJXP_XMLWriter", "catchError"), E_ALL & ~E_NOTICE );
//set_exception_handler(array("AJXP_XMLWriter", "catchException"));

$pServ = AJXP_PluginsService::getInstance();
ConfService::init();
$confPlugin = ConfService::getInstance()->confPluginSoftLoad($pServ);
$pServ->loadPluginsRegistry(AJXP_INSTALL_PATH."/plugins", $confPlugin);
ConfService::start();


$confStorageDriver = ConfService::getConfStorageImpl();
require_once($confStorageDriver->getUserClassFileName());
//session_name("AjaXplorer");
Expand Down
76 changes: 56 additions & 20 deletions core/src/core/classes/class.AJXP_PluginsService.php
Expand Up @@ -40,10 +40,25 @@ class AJXP_PluginsService
* @var AbstractConfDriver
*/
private $confStorage;
private $cacheStorage;
private $mixinsDoc;
private $mixinsXPath;


/**
* @return bool
*/
private function loadRegistryFromCacheService() {

$res = $this->cacheStorage->fetch("plugins_registry");

if (!$res) return false;

$this->registry = $res;

return true;
}

/**
* @return bool
*/
Expand All @@ -59,14 +74,22 @@ private function loadRegistryFromCache(){
}
require_once($fileName);
}
$kvCache = ConfService::getInstance()->getKeyValueCache();
$test = $kvCache->fetch("plugins_registry");
$test=FALSE;

//$test = CacheService::fetch("plugins_registry");

if($test !== FALSE) {
$this->registry = $test;
AJXP_Logger::debug(__CLASS__, __FUNCTION__, 'Loaded from cache');

$this->registry=$test;

}else{
AJXP_Logger::debug(__CLASS__, __FUNCTION__, 'Saving registry');
$res = AJXP_Utils::loadSerialFile(AJXP_PLUGINS_CACHE_FILE);
$this->registry = $res;
$kvCache->save("plugins_registry", $res);

//CacheService::save("plugins_registry", $res);

$this->registry=$res;
}
// Refresh streamWrapperPlugins
foreach ($this->registry as $plugs) {
Expand All @@ -76,6 +99,8 @@ private function loadRegistryFromCache(){
}
}
}


return true;
}else{
return false;
Expand All @@ -92,13 +117,18 @@ private function loadRegistryFromCache(){
* @param AbstractConfDriver $confStorage
* @param bool $rewriteCache Force a cache rewriting
*/
public function loadPluginsRegistry($pluginFolder, $confStorage, $rewriteCache = false)
public function loadPluginsRegistry($pluginFolder, $confStorage, $cacheStorage, $rewriteCache = false)
{
if(!$rewriteCache){
if(!empty($this->registry)){
return;
}
$this->cacheStorage = $cacheStorage;
if($this->loadRegistryFromCacheService()) {
return;
}
if($this->loadRegistryFromCache()){
CacheService::save("plugins_registry", $this->registry);
return;
}
}
Expand Down Expand Up @@ -138,6 +168,7 @@ public function loadPluginsRegistry($pluginFolder, $confStorage, $rewriteCache =
@unlink(AJXP_PLUGINS_QUERIES_CACHE);
}
}
$this->cacheStorage->save("plugins_registry", $this->registry);
}

/**
Expand Down Expand Up @@ -210,28 +241,32 @@ public static function clearPluginsCache(){
* @param array $pluginOptions
* @return AJXP_Plugin
*/
public function softLoad($pluginId, $pluginOptions)
public function softLoad($pluginId, $pluginOptions, $skipCache = false)
{
if(empty($this->registry)){
$this->loadRegistryFromCache();
}
// Try to get from cache
list($type, $name) = explode(".", $pluginId);
if(!empty($this->registry) && isSet($this->registry[$type][$name])) {
/**
* @var AJXP_Plugin $plugin
*/
$plugin = $this->registry[$type][$name];
$plugin->init($pluginOptions);
return clone $plugin;
}
if (!$skipCache)
{
if(empty($this->registry)){
$this->loadRegistryFromCache();
}

// Try to get from cache
list($type, $name) = explode(".", $pluginId);
if(!empty($this->registry) && isSet($this->registry[$type][$name])) {
/**
* @var AJXP_Plugin $plugin
*/
$plugin = $this->registry[$type][$name];
$plugin->init($pluginOptions);
return clone $plugin;
}
}

$plugin = new AJXP_Plugin($pluginId, AJXP_INSTALL_PATH."/".AJXP_PLUGINS_FOLDER."/".$pluginId);
$plugin->loadManifest();
$plugin = $this->instanciatePluginClass($plugin);
$plugin->loadConfigs(array()); // Load default
$plugin->init($pluginOptions);

return $plugin;
}

Expand All @@ -245,6 +280,7 @@ private function instanciatePluginClass($plugin)
{
$definition = $plugin->getClassFile();
if(!$definition) return $plugin;

$filename = AJXP_INSTALL_PATH."/".$definition["filename"];
$className = $definition["classname"];
if (is_file($filename)) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/core/classes/class.AuthService.php
Expand Up @@ -1147,7 +1147,7 @@ public static function getRole($roleId, $createIfNotExists = false)
public static function updateRole($roleObject, $userObject = null)
{
ConfService::getConfStorageImpl()->updateRole($roleObject, $userObject);
ConfService::getInstance()->getKeyValueCache()->deleteAll();
CacheService::deleteAll();
}
/**
* Delete a role by its id
Expand All @@ -1158,7 +1158,7 @@ public static function updateRole($roleObject, $userObject = null)
public static function deleteRole($roleId)
{
ConfService::getConfStorageImpl()->deleteRole($roleId);
ConfService::getInstance()->getKeyValueCache()->deleteAll();
CacheService::deleteAll();
}

public static function filterPluginParameters($pluginId, $params, $repoId = null)
Expand Down
88 changes: 88 additions & 0 deletions core/src/core/classes/class.CacheService.php
@@ -0,0 +1,88 @@
<?php
/*
* Copyright 2007-2013 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
* This file is part of Pydio.
*
* Pydio is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <http://pyd.io/>.
*/
defined('AJXP_EXEC') or die( 'Access not allowed');

/**
* Static access to the caching mechanism. Encapsulates the cacheDriver implementation
* @package Pydio
* @subpackage Core
*/
class CacheService
{

public static function contains($id) {
//var_dump('Cotnains' . $id);
$cacheDriver = ConfService::getCacheDriverImpl();

if ($cacheDriver) {
return $cacheDriver->contains($id);
}

return false;
}

public static function save($id, $object, $timelimit = 0 ) {
$cacheDriver = ConfService::getCacheDriverImpl();

if ($cacheDriver) {
return $cacheDriver->save($id, $object, $timelimit = 0);
} else {
AJXP_Logger::debug(__CLASS__,__FUNCTION__,'error '.$cacheDriver);
}

return false;
}

public static function fetch($id) {
//var_dump('Fetch' . $id);
$cacheDriver = ConfService::getCacheDriverImpl();

return false;
if ($cacheDriver) {
$data = $cacheDriver->fetch($id);
return $data;
}

return false;
}

public static function delete($id) {
//var_dump('Delete' . $id);
$cacheDriver = ConfService::getCacheDriverImpl();

if ($cacheDriver) {
return $cacheDriver->delete($id);
}

return false;
}

public static function deleteAll() {
//var_dump('Delete ALL' . $id);
$cacheDriver = ConfService::getCacheDriverImpl();

if ($cacheDriver) {
return $cacheDriver->deleteAll();
}

return false;
}
}

0 comments on commit 6a88906

Please sign in to comment.