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

Commit

Permalink
Use caching to agressively store directory listings, nodes metadata a…
Browse files Browse the repository at this point in the history
…nd nodes stats.

Introduced caching namespaces, we could even provide different backends for differents namespaces.
Todo: create a user namespace to flush only specific resources.
  • Loading branch information
cdujeu committed Apr 22, 2016
1 parent 2b717c1 commit ca2212b
Show file tree
Hide file tree
Showing 15 changed files with 433 additions and 90 deletions.
26 changes: 25 additions & 1 deletion core/src/core/classes/class.AJXP_Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,22 @@ public function loadNodeInfo($forceRefresh = false, $contextNode = false, $detai
if($this->nodeInfoLoaded && $this->nodeInfoLevel != $details){
$forceRefresh = true;
}
if($this->nodeInfoLoaded && !$forceRefresh) return;
if($this->nodeInfoLoaded && !$forceRefresh){
return;
}
if (!empty($this->_wrapperClassName)) {
$registered = AJXP_PluginsService::getInstance()->getRegisteredWrappers();
if (!isSet($registered[$this->getScheme()])) {
$driver = $this->getDriver();
if(is_object($driver)) $driver->detectStreamWrapper(true);
}
}
AJXP_Controller::applyHook("node.info.start", array(&$this, $contextNode, $details));
if($this->nodeInfoLoaded && !$forceRefresh){
return;
}
AJXP_Controller::applyHook("node.info", array(&$this, $contextNode, $details));
AJXP_Controller::applyHook("node.info.end", array(&$this, $contextNode, $details));
$this->nodeInfoLoaded = true;
$this->nodeInfoLevel = $details;
}
Expand Down Expand Up @@ -519,6 +526,23 @@ public function mergeMetadata($metadata, $mergeValues = false)
}
}

/**
* Return all metadata loaded during node.info, mainly used for caching.
* @return array
*/
public function getNodeInfoMeta(){
return $this->_metadata;
}

/**
* Set nodeInfoLoaded to true from external.
* @param string $level
*/
public function setInfoLoaded($level){
$this->nodeInfoLoaded = true;
$this->nodeInfoLevel = $level;
}

/**
* Magic getter for metadata
* @param $varName
Expand Down
7 changes: 5 additions & 2 deletions core/src/core/classes/class.AJXP_PluginsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class AJXP_PluginsService
* @var AbstractConfDriver
*/
private $confStorage;
/**
* @var AbstractCacheDriver
*/
private $cacheStorage;
private $mixinsDoc;
private $mixinsXPath;
Expand All @@ -65,7 +68,7 @@ private function _loadRegistryFromCache(){

// Retrieving Registry from Server Cache
if ($this->cacheStorage) {
$res = $this->cacheStorage->fetch('plugins_registry');
$res = $this->cacheStorage->fetch(AJXP_CACHE_SERVICE_NS_SHARED, 'plugins_registry');

$this->registry=$res;
}
Expand Down Expand Up @@ -118,7 +121,7 @@ public function loadPluginsRegistryFromCache($cacheStorage = null) {
*/
public function savePluginsRegistryToCache() {
if (!empty ($this->cacheStorage)) {
$this->cacheStorage->save("plugins_registry", $this->registry);
$this->cacheStorage->save(AJXP_CACHE_SERVICE_NS_SHARED, "plugins_registry", $this->registry);
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/core/classes/class.AuthService.php
Original file line number Diff line number Diff line change
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);
CacheService::deleteAll();
CacheService::deleteAll(AJXP_CACHE_SERVICE_NS_SHARED);
}
/**
* 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);
CacheService::deleteAll();
CacheService::deleteAll(AJXP_CACHE_SERVICE_NS_SHARED);
}

public static function filterPluginParameters($pluginId, $params, $repoId = null)
Expand Down
25 changes: 15 additions & 10 deletions core/src/core/classes/class.CacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,72 +28,77 @@
class CacheService
{
/**
* @param $namespace
* @param $id
* @return bool
*/
public static function contains($id) {
public static function contains($namespace, $id) {
$cacheDriver = ConfService::getCacheDriverImpl();

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

return false;
}

/**
* @param $namespace
* @param $id
* @param $object
* @param int $timelimit
* @return bool
*/
public static function save($id, $object, $timelimit = 0 ) {
public static function save($namespace, $id, $object, $timelimit = 0) {
$cacheDriver = ConfService::getCacheDriverImpl();

if ($cacheDriver) {
return $cacheDriver->save($id, $object, $timelimit);
return $cacheDriver->save($namespace, $id, $object, $timelimit);
}

return false;
}

/**
* @param $namespace
* @param $id
* @return bool|mixed
*/
public static function fetch($id) {
public static function fetch($namespace, $id) {
$cacheDriver = ConfService::getCacheDriverImpl();

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

return false;
}

/**
* @param $namespace
* @param $id
* @return bool
*/
public static function delete($id) {
public static function delete($namespace, $id) {
$cacheDriver = ConfService::getCacheDriverImpl();

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

return false;
}

/**
* @param $namespace
* @return bool
*/
public static function deleteAll() {
public static function deleteAll($namespace) {
$cacheDriver = ConfService::getCacheDriverImpl();

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

return false;
Expand Down
19 changes: 10 additions & 9 deletions core/src/core/classes/class.ConfService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class ConfService

private $booter;
private $confPlugin;
/**
* @var AbstractCacheDriver
*/
private $cachePlugin;
private $errors = array();
private $configs = array();
Expand All @@ -40,7 +43,6 @@ class ConfService
private $contextCharset;

/**
* @param AJXP_PluginsService $ajxpPluginService
* @return AbstractConfDriver
*/
public function confPluginSoftLoad()
Expand All @@ -54,7 +56,6 @@ public function confPluginSoftLoad()
}

/**
* @param AJXP_PluginsService $ajxpPluginService
* @return AbstractCacheDriver
*/
public function cachePluginSoftLoad()
Expand Down Expand Up @@ -192,7 +193,7 @@ public function getContextRepositoryId(){
public static function clearAllCaches(){
AJXP_PluginsService::clearPluginsCache();
self::clearMessagesCache();
CacheService::deleteAll();
CacheService::deleteAll(AJXP_CACHE_SERVICE_NS_SHARED);
if(function_exists('opcache_reset')){
opcache_reset();
}
Expand Down Expand Up @@ -332,7 +333,7 @@ public static function getFilteredXMLRegistry($extendedVersion = true, $clone =

if($useCache){
$cacheKey = self::getRegistryCacheKey($extendedVersion);
$cachedXml = CacheService::fetch($cacheKey);
$cachedXml = CacheService::fetch(AJXP_CACHE_SERVICE_NS_SHARED, $cacheKey);
if($cachedXml !== false){
$registry = new DOMDocument("1.0", "utf-8");
$registry->loadXML($cachedXml);
Expand All @@ -352,7 +353,7 @@ public static function getFilteredXMLRegistry($extendedVersion = true, $clone =
}

if($useCache && isSet($cacheKey)){
CacheService::save($cacheKey, $registry->saveXML());
CacheService::save(AJXP_CACHE_SERVICE_NS_SHARED, $cacheKey, $registry->saveXML());
}

if($clone){
Expand Down Expand Up @@ -598,7 +599,7 @@ public function invalidateLoadedRepositories()
{
if(isSet($_SESSION["REPOSITORIES"])) unset($_SESSION["REPOSITORIES"]);
$this->configs["REPOSITORIES"] = null;
CacheService::deleteAll();
CacheService::deleteAll(AJXP_CACHE_SERVICE_NS_SHARED);
}

private function cacheRepository($repoId, $repository){
Expand Down Expand Up @@ -1063,20 +1064,20 @@ public function getRepositoryByIdInst($repoId)
if (iSset($this->configs["REPOSITORY"]) && $this->configs["REPOSITORY"]->getId()."" == $repoId) {
return $this->configs["REPOSITORY"];
}
$test = CacheService::fetch("repository:".$repoId);
$test = CacheService::fetch(AJXP_CACHE_SERVICE_NS_SHARED, "repository:" . $repoId);
if($test !== false){
return $test;
}
$test = $this->getConfStorageImpl()->getRepositoryById($repoId);
if($test != null) {
CacheService::save("repository:".$repoId, $test);
CacheService::save(AJXP_CACHE_SERVICE_NS_SHARED, "repository:" . $repoId, $test);
return $test;
}
// Finally try to search in default repositories
if (isSet($this->configs["DEFAULT_REPOSITORIES"]) && isSet($this->configs["DEFAULT_REPOSITORIES"][$repoId])) {
$repo = self::createRepositoryFromArray($repoId, $this->configs["DEFAULT_REPOSITORIES"][$repoId]);
$repo->setWriteable(false);
CacheService::save("repository:".$repoId, $repo);
CacheService::save(AJXP_CACHE_SERVICE_NS_SHARED, "repository:" . $repoId, $repo);
return $repo;
}
$hookedRepo = null;
Expand Down
6 changes: 3 additions & 3 deletions core/src/plugins/access.s3/class.s3CacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class s3CacheService implements \Aws\CacheInterface
* @return mixed|null Returns the value or null if not found.
*/
public function get($key) {
return \CacheService::fetch($key);
return \CacheService::fetch(AJXP_CACHE_SERVICE_NS_SHARED, $key);
}

/**
Expand All @@ -43,7 +43,7 @@ public function get($key) {
* to 0 to allow an unlimited lifetime.
*/
public function set($key, $value, $ttl = 0) {
\CacheService::save($key, $value, $ttl);
\CacheService::save(AJXP_CACHE_SERVICE_NS_SHARED, $key, $value, $ttl);
}

/**
Expand All @@ -52,6 +52,6 @@ public function set($key, $value, $ttl = 0) {
* @param string $key Key to remove.
*/
public function remove($key) {
\CacheService::delete($key);
\CacheService::delete(AJXP_CACHE_SERVICE_NS_SHARED, $key);
}
}
Loading

0 comments on commit ca2212b

Please sign in to comment.