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

Commit

Permalink
Adding local cache per instance to MemorySafe and removing time limit…
Browse files Browse the repository at this point in the history
… on nodes cache
  • Loading branch information
ghecquet committed Jan 18, 2017
1 parent 5908f02 commit 52cf15c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
20 changes: 15 additions & 5 deletions core/src/plugins/core.auth/MemorySafe.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
use Pydio\Core\Services\SessionService;
use Pydio\Core\Utils\Crypto;
use Pydio\Core\Utils\Vars\OptionsHelper;


use Doctrine\Common\Cache\ArrayCache;

defined('AJXP_EXEC') or die( 'Access not allowed');

Expand All @@ -40,6 +39,7 @@ class MemorySafe
const SAFE_CREDENTIALS_KEY = "PYDIO_SAFE_CREDENTIALS";

private static $instances;
private static $cache;

private $instanceId = "";
private $user;
Expand Down Expand Up @@ -239,6 +239,14 @@ public static function tryLoadingCredentialsFromSources($ctx)
$user = $password = "";
$optionsPrefix = "";
$repository = $ctx->getRepository();
$instanceId = self::getInstanceId($ctx);
$instanceId = empty($instanceId) ? "__DEFAULT__" : $instanceId;

$cache = self::$cache;
if (isset($cache[$instanceId])) {
return $cache[$instanceId];
}

if ($repository->getAccessType() == "ftp") {
$optionsPrefix = "FTP_";
}
Expand Down Expand Up @@ -275,16 +283,18 @@ public static function tryLoadingCredentialsFromSources($ctx)
}
}
if ($user=="" && ( $repository->getContextOption($ctx, "USE_SESSION_CREDENTIALS") || $storeCreds || self::getInstance()->forceSessionCredentials )) {
$instanceId = $instanceId = self::getInstanceId($ctx);
$instanceId = empty($instanceId) ? "" : $instanceId;
$safeCred = MemorySafe::loadCredentials($instanceId);
if ($safeCred !== false) {
$user = $safeCred["user"];
$password = $safeCred["password"];
}
}
return array("user" => $user, "password" => $password);

$res = ["user" => $user, "password" => $password];

self::$cache[$instanceId] = $res;

return $res;
}

/*******************/
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/core.cache/AbstractCacheDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static function getOptionsForNode($node, $cacheType, $details = ''){

$options = [
"id" => $cacheType."://".$repo->getId().$subPath.$node->getPath().($details?"##$details":""),
"timelimit" => $repo->getContextOption($ctx, "CACHE_TIMELIMIT", 5)
"timelimit" => $repo->getContextOption($ctx, "CACHE_TIMELIMIT", 0)
];
return $options;
}
Expand Down Expand Up @@ -405,4 +405,4 @@ public function __destruct()
}
}

}
}

0 comments on commit 52cf15c

Please sign in to comment.