This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expand Doctrine caches implementation to add "deleteKeyStartingBy" wh…
…en possible (currently only APC and Redis). If this feature is supported, activate the nodes cache layer (otherwise we cannot prune a full branch of the filesystem tree).
- Loading branch information
Showing
7 changed files
with
275 additions
and
36 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
39 changes: 39 additions & 0 deletions
39
core/src/plugins/cache.doctrine/ext/PatternClearableCache.php
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,39 @@ | ||
<?php | ||
/* | ||
* Copyright 2007-2015 Abstrium <contact (at) pydio.com> | ||
* 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/>. | ||
*/ | ||
namespace Pydio\Plugins\Cache\Doctrine\Ext; | ||
|
||
defined('AJXP_EXEC') or die('Access not allowed'); | ||
|
||
interface PatternClearableCache{ | ||
|
||
/** | ||
* @param string $pattern | ||
* @return bool | ||
*/ | ||
public function deleteKeysStartingWith($pattern); | ||
|
||
/** | ||
* @param string $namespace | ||
* @return void | ||
*/ | ||
public function setNamespace($namespace); | ||
|
||
} |
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,66 @@ | ||
<?php | ||
/* | ||
* Copyright 2007-2015 Abstrium <contact (at) pydio.com> | ||
* 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/>. | ||
*/ | ||
namespace Pydio\Plugins\Cache\Doctrine\Ext; | ||
|
||
defined('AJXP_EXEC') or die('Access not allowed'); | ||
require_once "PatternClearableCache.php"; | ||
|
||
class PydioApcuCache extends \Doctrine\Common\Cache\ApcuCache implements PatternClearableCache | ||
{ | ||
protected $internalNamespace; | ||
protected $internalNamespaceVersion; | ||
|
||
/** | ||
* Prefixes the passed id with the configured namespace value. | ||
* | ||
* @param string $id The id to namespace. | ||
* | ||
* @return string The namespaced id. | ||
*/ | ||
private function getNamespacedId($id) | ||
{ | ||
return sprintf('%s\['.preg_quote($id, "/"), $this->internalNamespace); | ||
} | ||
|
||
/** | ||
* @param string $pattern | ||
* @return bool | ||
*/ | ||
public function deleteKeysStartingWith($pattern) | ||
{ | ||
$pattern = '/^'.$this->getNamespacedId($pattern).'/'; | ||
//SAMPLE /^pydio-unique-id_nodes_\[list\:\/\/1/ | ||
$iterator = new APCIterator('user', $pattern); | ||
foreach ($iterator as $data) { | ||
$res = $this->doDelete($data['key']); | ||
} | ||
} | ||
|
||
/** | ||
* @param string $namespace | ||
* @return void | ||
*/ | ||
public function setNamespace($namespace) | ||
{ | ||
parent::setNamespace($namespace); | ||
$this->internalNamespace = $namespace; | ||
} | ||
} |
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,83 @@ | ||
<?php | ||
/* | ||
* Copyright 2007-2015 Abstrium <contact (at) pydio.com> | ||
* 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/>. | ||
*/ | ||
namespace Pydio\Plugins\Cache\Doctrine\Ext; | ||
defined('AJXP_EXEC') or die('Access not allowed'); | ||
|
||
require_once "PatternClearableCache.php"; | ||
use Redis; | ||
|
||
|
||
class PydioRedisCache extends \Doctrine\Common\Cache\RedisCache implements PatternClearableCache | ||
{ | ||
/** | ||
* @var Redis | ||
*/ | ||
protected $internalRedis; | ||
protected $internalNamespace; | ||
protected $internalNamespaceVersion; | ||
|
||
|
||
public function setRedis($redis){ | ||
parent::setRedis($redis); | ||
$this->internalRedis = $redis; | ||
} | ||
|
||
/** | ||
* Prefixes the passed id with the configured namespace value. | ||
* | ||
* @param string $id The id to namespace. | ||
* | ||
* @return string The namespaced id. | ||
*/ | ||
private function getNamespacedId($id) | ||
{ | ||
// Escape redis MATCH special characters | ||
$id = str_replace(array("?", "*", "[", "]", "^", "-"), array("\?", "\*", "\[", "\]", "\^", "\-"), $id); | ||
return sprintf('%s\['.$id.'*', $this->internalNamespace); | ||
} | ||
|
||
|
||
/** | ||
* @param string $pattern | ||
* @return bool | ||
*/ | ||
public function deleteKeysStartingWith($pattern) | ||
{ | ||
$pattern = $this->getNamespacedId($pattern); | ||
$it = NULL; /* Initialize our iterator to NULL */ | ||
$this->internalRedis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY); /* retry when we get no keys back */ | ||
while($arr_keys = $this->internalRedis->scan($it, $pattern)) { | ||
foreach($arr_keys as $str_key) { | ||
$this->doDelete($str_key); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param string $namespace | ||
* @return void | ||
*/ | ||
public function setNamespace($namespace) | ||
{ | ||
parent::setNamespace($namespace); | ||
$this->internalNamespace = $namespace; | ||
} | ||
} |
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
Oops, something went wrong.