@@ -26,31 +26,31 @@ |
||
26 | 26 | namespace OC\Template; |
27 | 27 | |
28 | 28 | class CSSResourceLocator extends ResourceLocator { |
29 | - /** |
|
30 | - * @param string $style |
|
31 | - */ |
|
32 | - public function doFind($style) { |
|
33 | - if (strpos($style, '3rdparty') === 0 |
|
34 | - && $this->appendIfExist($this->thirdpartyroot, $style.'.css') |
|
35 | - || $this->appendIfExist($this->serverroot, $style.'.css') |
|
36 | - || $this->appendIfExist($this->serverroot, 'core/'.$style.'.css') |
|
37 | - ) { |
|
38 | - return; |
|
39 | - } |
|
40 | - $app = substr($style, 0, strpos($style, '/')); |
|
41 | - $style = substr($style, strpos($style, '/')+1); |
|
42 | - $app_path = \OC_App::getAppPath($app); |
|
43 | - $app_url = \OC_App::getAppWebPath($app); |
|
44 | - $this->append($app_path, $style.'.css', $app_url); |
|
45 | - } |
|
29 | + /** |
|
30 | + * @param string $style |
|
31 | + */ |
|
32 | + public function doFind($style) { |
|
33 | + if (strpos($style, '3rdparty') === 0 |
|
34 | + && $this->appendIfExist($this->thirdpartyroot, $style.'.css') |
|
35 | + || $this->appendIfExist($this->serverroot, $style.'.css') |
|
36 | + || $this->appendIfExist($this->serverroot, 'core/'.$style.'.css') |
|
37 | + ) { |
|
38 | + return; |
|
39 | + } |
|
40 | + $app = substr($style, 0, strpos($style, '/')); |
|
41 | + $style = substr($style, strpos($style, '/')+1); |
|
42 | + $app_path = \OC_App::getAppPath($app); |
|
43 | + $app_url = \OC_App::getAppWebPath($app); |
|
44 | + $this->append($app_path, $style.'.css', $app_url); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param string $style |
|
49 | - */ |
|
50 | - public function doFindTheme($style) { |
|
51 | - $theme_dir = 'themes/'.$this->theme.'/'; |
|
52 | - $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$style.'.css') |
|
53 | - || $this->appendIfExist($this->serverroot, $theme_dir.$style.'.css') |
|
54 | - || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$style.'.css'); |
|
55 | - } |
|
47 | + /** |
|
48 | + * @param string $style |
|
49 | + */ |
|
50 | + public function doFindTheme($style) { |
|
51 | + $theme_dir = 'themes/'.$this->theme.'/'; |
|
52 | + $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$style.'.css') |
|
53 | + || $this->appendIfExist($this->serverroot, $theme_dir.$style.'.css') |
|
54 | + || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$style.'.css'); |
|
55 | + } |
|
56 | 56 | } |
@@ -38,7 +38,7 @@ |
||
38 | 38 | return; |
39 | 39 | } |
40 | 40 | $app = substr($style, 0, strpos($style, '/')); |
41 | - $style = substr($style, strpos($style, '/')+1); |
|
41 | + $style = substr($style, strpos($style, '/') + 1); |
|
42 | 42 | $app_path = \OC_App::getAppPath($app); |
43 | 43 | $app_url = \OC_App::getAppWebPath($app); |
44 | 44 | $this->append($app_path, $style.'.css', $app_url); |
@@ -26,54 +26,54 @@ |
||
26 | 26 | namespace OC\Template; |
27 | 27 | |
28 | 28 | class JSResourceLocator extends ResourceLocator { |
29 | - /** |
|
30 | - * @param string $script |
|
31 | - */ |
|
32 | - public function doFind($script) { |
|
33 | - $theme_dir = 'themes/'.$this->theme.'/'; |
|
34 | - if (strpos($script, '3rdparty') === 0 |
|
35 | - && $this->appendIfExist($this->thirdpartyroot, $script.'.js')) { |
|
36 | - return; |
|
37 | - } |
|
29 | + /** |
|
30 | + * @param string $script |
|
31 | + */ |
|
32 | + public function doFind($script) { |
|
33 | + $theme_dir = 'themes/'.$this->theme.'/'; |
|
34 | + if (strpos($script, '3rdparty') === 0 |
|
35 | + && $this->appendIfExist($this->thirdpartyroot, $script.'.js')) { |
|
36 | + return; |
|
37 | + } |
|
38 | 38 | |
39 | - if (strpos($script, '/l10n/') !== false) { |
|
40 | - // For language files we try to load them all, so themes can overwrite |
|
41 | - // single l10n strings without having to translate all of them. |
|
42 | - $found = 0; |
|
43 | - $found += $this->appendIfExist($this->serverroot, 'core/'.$script.'.js'); |
|
44 | - $found += $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js'); |
|
45 | - $found += $this->appendIfExist($this->serverroot, $script.'.js'); |
|
46 | - $found += $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js'); |
|
47 | - $found += $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js'); |
|
39 | + if (strpos($script, '/l10n/') !== false) { |
|
40 | + // For language files we try to load them all, so themes can overwrite |
|
41 | + // single l10n strings without having to translate all of them. |
|
42 | + $found = 0; |
|
43 | + $found += $this->appendIfExist($this->serverroot, 'core/'.$script.'.js'); |
|
44 | + $found += $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js'); |
|
45 | + $found += $this->appendIfExist($this->serverroot, $script.'.js'); |
|
46 | + $found += $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js'); |
|
47 | + $found += $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js'); |
|
48 | 48 | |
49 | - if ($found) { |
|
50 | - return; |
|
51 | - } |
|
52 | - } else if ($this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js') |
|
53 | - || $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js') |
|
54 | - || $this->appendIfExist($this->serverroot, $script.'.js') |
|
55 | - || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js') |
|
56 | - || $this->appendIfExist($this->serverroot, 'core/'.$script.'.js') |
|
57 | - ) { |
|
58 | - return; |
|
59 | - } |
|
49 | + if ($found) { |
|
50 | + return; |
|
51 | + } |
|
52 | + } else if ($this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js') |
|
53 | + || $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js') |
|
54 | + || $this->appendIfExist($this->serverroot, $script.'.js') |
|
55 | + || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js') |
|
56 | + || $this->appendIfExist($this->serverroot, 'core/'.$script.'.js') |
|
57 | + ) { |
|
58 | + return; |
|
59 | + } |
|
60 | 60 | |
61 | - $app = substr($script, 0, strpos($script, '/')); |
|
62 | - $script = substr($script, strpos($script, '/')+1); |
|
63 | - $app_path = \OC_App::getAppPath($app); |
|
64 | - $app_url = \OC_App::getAppWebPath($app); |
|
61 | + $app = substr($script, 0, strpos($script, '/')); |
|
62 | + $script = substr($script, strpos($script, '/')+1); |
|
63 | + $app_path = \OC_App::getAppPath($app); |
|
64 | + $app_url = \OC_App::getAppWebPath($app); |
|
65 | 65 | |
66 | - // missing translations files fill be ignored |
|
67 | - if (strpos($script, 'l10n/') === 0) { |
|
68 | - $this->appendIfExist($app_path, $script . '.js', $app_url); |
|
69 | - return; |
|
70 | - } |
|
71 | - $this->append($app_path, $script . '.js', $app_url); |
|
72 | - } |
|
66 | + // missing translations files fill be ignored |
|
67 | + if (strpos($script, 'l10n/') === 0) { |
|
68 | + $this->appendIfExist($app_path, $script . '.js', $app_url); |
|
69 | + return; |
|
70 | + } |
|
71 | + $this->append($app_path, $script . '.js', $app_url); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @param string $script |
|
76 | - */ |
|
77 | - public function doFindTheme($script) { |
|
78 | - } |
|
74 | + /** |
|
75 | + * @param string $script |
|
76 | + */ |
|
77 | + public function doFindTheme($script) { |
|
78 | + } |
|
79 | 79 | } |
@@ -59,16 +59,16 @@ |
||
59 | 59 | } |
60 | 60 | |
61 | 61 | $app = substr($script, 0, strpos($script, '/')); |
62 | - $script = substr($script, strpos($script, '/')+1); |
|
62 | + $script = substr($script, strpos($script, '/') + 1); |
|
63 | 63 | $app_path = \OC_App::getAppPath($app); |
64 | 64 | $app_url = \OC_App::getAppWebPath($app); |
65 | 65 | |
66 | 66 | // missing translations files fill be ignored |
67 | 67 | if (strpos($script, 'l10n/') === 0) { |
68 | - $this->appendIfExist($app_path, $script . '.js', $app_url); |
|
68 | + $this->appendIfExist($app_path, $script.'.js', $app_url); |
|
69 | 69 | return; |
70 | 70 | } |
71 | - $this->append($app_path, $script . '.js', $app_url); |
|
71 | + $this->append($app_path, $script.'.js', $app_url); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -31,58 +31,58 @@ |
||
31 | 31 | */ |
32 | 32 | class CappedMemoryCache implements ICache, \ArrayAccess { |
33 | 33 | |
34 | - private $capacity; |
|
35 | - private $cache = []; |
|
36 | - |
|
37 | - public function __construct($capacity = 512) { |
|
38 | - $this->capacity = $capacity; |
|
39 | - } |
|
40 | - |
|
41 | - public function hasKey($key) { |
|
42 | - return isset($this->cache[$key]); |
|
43 | - } |
|
44 | - |
|
45 | - public function get($key) { |
|
46 | - return isset($this->cache[$key]) ? $this->cache[$key] : null; |
|
47 | - } |
|
48 | - |
|
49 | - public function set($key, $value, $ttl = 0) { |
|
50 | - $this->cache[$key] = $value; |
|
51 | - $this->garbageCollect(); |
|
52 | - } |
|
53 | - |
|
54 | - public function remove($key) { |
|
55 | - unset($this->cache[$key]); |
|
56 | - return true; |
|
57 | - } |
|
58 | - |
|
59 | - public function clear($prefix = '') { |
|
60 | - $this->cache = []; |
|
61 | - return true; |
|
62 | - } |
|
63 | - |
|
64 | - public function offsetExists($offset) { |
|
65 | - return $this->hasKey($offset); |
|
66 | - } |
|
67 | - |
|
68 | - public function &offsetGet($offset) { |
|
69 | - return $this->cache[$offset]; |
|
70 | - } |
|
71 | - |
|
72 | - public function offsetSet($offset, $value) { |
|
73 | - $this->set($offset, $value); |
|
74 | - } |
|
75 | - |
|
76 | - public function offsetUnset($offset) { |
|
77 | - $this->remove($offset); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - private function garbageCollect() { |
|
82 | - while (count($this->cache) > $this->capacity) { |
|
83 | - reset($this->cache); |
|
84 | - $key = key($this->cache); |
|
85 | - $this->remove($key); |
|
86 | - } |
|
87 | - } |
|
34 | + private $capacity; |
|
35 | + private $cache = []; |
|
36 | + |
|
37 | + public function __construct($capacity = 512) { |
|
38 | + $this->capacity = $capacity; |
|
39 | + } |
|
40 | + |
|
41 | + public function hasKey($key) { |
|
42 | + return isset($this->cache[$key]); |
|
43 | + } |
|
44 | + |
|
45 | + public function get($key) { |
|
46 | + return isset($this->cache[$key]) ? $this->cache[$key] : null; |
|
47 | + } |
|
48 | + |
|
49 | + public function set($key, $value, $ttl = 0) { |
|
50 | + $this->cache[$key] = $value; |
|
51 | + $this->garbageCollect(); |
|
52 | + } |
|
53 | + |
|
54 | + public function remove($key) { |
|
55 | + unset($this->cache[$key]); |
|
56 | + return true; |
|
57 | + } |
|
58 | + |
|
59 | + public function clear($prefix = '') { |
|
60 | + $this->cache = []; |
|
61 | + return true; |
|
62 | + } |
|
63 | + |
|
64 | + public function offsetExists($offset) { |
|
65 | + return $this->hasKey($offset); |
|
66 | + } |
|
67 | + |
|
68 | + public function &offsetGet($offset) { |
|
69 | + return $this->cache[$offset]; |
|
70 | + } |
|
71 | + |
|
72 | + public function offsetSet($offset, $value) { |
|
73 | + $this->set($offset, $value); |
|
74 | + } |
|
75 | + |
|
76 | + public function offsetUnset($offset) { |
|
77 | + $this->remove($offset); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + private function garbageCollect() { |
|
82 | + while (count($this->cache) > $this->capacity) { |
|
83 | + reset($this->cache); |
|
84 | + $key = key($this->cache); |
|
85 | + $this->remove($key); |
|
86 | + } |
|
87 | + } |
|
88 | 88 | } |
@@ -33,170 +33,170 @@ |
||
33 | 33 | |
34 | 34 | class File implements ICache { |
35 | 35 | |
36 | - /** @var View */ |
|
37 | - protected $storage; |
|
36 | + /** @var View */ |
|
37 | + protected $storage; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Returns the cache storage for the logged in user |
|
41 | - * |
|
42 | - * @return \OC\Files\View cache storage |
|
43 | - * @throws \OC\ForbiddenException |
|
44 | - * @throws \OC\User\NoUserException |
|
45 | - */ |
|
46 | - protected function getStorage() { |
|
47 | - if (isset($this->storage)) { |
|
48 | - return $this->storage; |
|
49 | - } |
|
50 | - if (\OC_User::isLoggedIn()) { |
|
51 | - $rootView = new View(); |
|
52 | - $user = \OC::$server->getUserSession()->getUser(); |
|
53 | - Filesystem::initMountPoints($user->getUID()); |
|
54 | - if (!$rootView->file_exists('/' . $user->getUID() . '/cache')) { |
|
55 | - $rootView->mkdir('/' . $user->getUID() . '/cache'); |
|
56 | - } |
|
57 | - $this->storage = new View('/' . $user->getUID() . '/cache'); |
|
58 | - return $this->storage; |
|
59 | - } else { |
|
60 | - \OCP\Util::writeLog('core', 'Can\'t get cache storage, user not logged in', \OCP\Util::ERROR); |
|
61 | - throw new \OC\ForbiddenException('Can\t get cache storage, user not logged in'); |
|
62 | - } |
|
63 | - } |
|
39 | + /** |
|
40 | + * Returns the cache storage for the logged in user |
|
41 | + * |
|
42 | + * @return \OC\Files\View cache storage |
|
43 | + * @throws \OC\ForbiddenException |
|
44 | + * @throws \OC\User\NoUserException |
|
45 | + */ |
|
46 | + protected function getStorage() { |
|
47 | + if (isset($this->storage)) { |
|
48 | + return $this->storage; |
|
49 | + } |
|
50 | + if (\OC_User::isLoggedIn()) { |
|
51 | + $rootView = new View(); |
|
52 | + $user = \OC::$server->getUserSession()->getUser(); |
|
53 | + Filesystem::initMountPoints($user->getUID()); |
|
54 | + if (!$rootView->file_exists('/' . $user->getUID() . '/cache')) { |
|
55 | + $rootView->mkdir('/' . $user->getUID() . '/cache'); |
|
56 | + } |
|
57 | + $this->storage = new View('/' . $user->getUID() . '/cache'); |
|
58 | + return $this->storage; |
|
59 | + } else { |
|
60 | + \OCP\Util::writeLog('core', 'Can\'t get cache storage, user not logged in', \OCP\Util::ERROR); |
|
61 | + throw new \OC\ForbiddenException('Can\t get cache storage, user not logged in'); |
|
62 | + } |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @param string $key |
|
67 | - * @return mixed|null |
|
68 | - * @throws \OC\ForbiddenException |
|
69 | - */ |
|
70 | - public function get($key) { |
|
71 | - $result = null; |
|
72 | - if ($this->hasKey($key)) { |
|
73 | - $storage = $this->getStorage(); |
|
74 | - $result = $storage->file_get_contents($key); |
|
75 | - } |
|
76 | - return $result; |
|
77 | - } |
|
65 | + /** |
|
66 | + * @param string $key |
|
67 | + * @return mixed|null |
|
68 | + * @throws \OC\ForbiddenException |
|
69 | + */ |
|
70 | + public function get($key) { |
|
71 | + $result = null; |
|
72 | + if ($this->hasKey($key)) { |
|
73 | + $storage = $this->getStorage(); |
|
74 | + $result = $storage->file_get_contents($key); |
|
75 | + } |
|
76 | + return $result; |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Returns the size of the stored/cached data |
|
81 | - * |
|
82 | - * @param string $key |
|
83 | - * @return int |
|
84 | - */ |
|
85 | - public function size($key) { |
|
86 | - $result = 0; |
|
87 | - if ($this->hasKey($key)) { |
|
88 | - $storage = $this->getStorage(); |
|
89 | - $result = $storage->filesize($key); |
|
90 | - } |
|
91 | - return $result; |
|
92 | - } |
|
79 | + /** |
|
80 | + * Returns the size of the stored/cached data |
|
81 | + * |
|
82 | + * @param string $key |
|
83 | + * @return int |
|
84 | + */ |
|
85 | + public function size($key) { |
|
86 | + $result = 0; |
|
87 | + if ($this->hasKey($key)) { |
|
88 | + $storage = $this->getStorage(); |
|
89 | + $result = $storage->filesize($key); |
|
90 | + } |
|
91 | + return $result; |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @param string $key |
|
96 | - * @param mixed $value |
|
97 | - * @param int $ttl |
|
98 | - * @return bool|mixed |
|
99 | - * @throws \OC\ForbiddenException |
|
100 | - */ |
|
101 | - public function set($key, $value, $ttl = 0) { |
|
102 | - $storage = $this->getStorage(); |
|
103 | - $result = false; |
|
104 | - // unique id to avoid chunk collision, just in case |
|
105 | - $uniqueId = \OC::$server->getSecureRandom()->generate( |
|
106 | - 16, |
|
107 | - ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER |
|
108 | - ); |
|
94 | + /** |
|
95 | + * @param string $key |
|
96 | + * @param mixed $value |
|
97 | + * @param int $ttl |
|
98 | + * @return bool|mixed |
|
99 | + * @throws \OC\ForbiddenException |
|
100 | + */ |
|
101 | + public function set($key, $value, $ttl = 0) { |
|
102 | + $storage = $this->getStorage(); |
|
103 | + $result = false; |
|
104 | + // unique id to avoid chunk collision, just in case |
|
105 | + $uniqueId = \OC::$server->getSecureRandom()->generate( |
|
106 | + 16, |
|
107 | + ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER |
|
108 | + ); |
|
109 | 109 | |
110 | - // use part file to prevent hasKey() to find the key |
|
111 | - // while it is being written |
|
112 | - $keyPart = $key . '.' . $uniqueId . '.part'; |
|
113 | - if ($storage and $storage->file_put_contents($keyPart, $value)) { |
|
114 | - if ($ttl === 0) { |
|
115 | - $ttl = 86400; // 60*60*24 |
|
116 | - } |
|
117 | - $result = $storage->touch($keyPart, time() + $ttl); |
|
118 | - $result &= $storage->rename($keyPart, $key); |
|
119 | - } |
|
120 | - return $result; |
|
121 | - } |
|
110 | + // use part file to prevent hasKey() to find the key |
|
111 | + // while it is being written |
|
112 | + $keyPart = $key . '.' . $uniqueId . '.part'; |
|
113 | + if ($storage and $storage->file_put_contents($keyPart, $value)) { |
|
114 | + if ($ttl === 0) { |
|
115 | + $ttl = 86400; // 60*60*24 |
|
116 | + } |
|
117 | + $result = $storage->touch($keyPart, time() + $ttl); |
|
118 | + $result &= $storage->rename($keyPart, $key); |
|
119 | + } |
|
120 | + return $result; |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * @param string $key |
|
125 | - * @return bool |
|
126 | - * @throws \OC\ForbiddenException |
|
127 | - */ |
|
128 | - public function hasKey($key) { |
|
129 | - $storage = $this->getStorage(); |
|
130 | - if ($storage && $storage->is_file($key) && $storage->isReadable($key)) { |
|
131 | - return true; |
|
132 | - } |
|
133 | - return false; |
|
134 | - } |
|
123 | + /** |
|
124 | + * @param string $key |
|
125 | + * @return bool |
|
126 | + * @throws \OC\ForbiddenException |
|
127 | + */ |
|
128 | + public function hasKey($key) { |
|
129 | + $storage = $this->getStorage(); |
|
130 | + if ($storage && $storage->is_file($key) && $storage->isReadable($key)) { |
|
131 | + return true; |
|
132 | + } |
|
133 | + return false; |
|
134 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * @param string $key |
|
138 | - * @return bool|mixed |
|
139 | - * @throws \OC\ForbiddenException |
|
140 | - */ |
|
141 | - public function remove($key) { |
|
142 | - $storage = $this->getStorage(); |
|
143 | - if (!$storage) { |
|
144 | - return false; |
|
145 | - } |
|
146 | - return $storage->unlink($key); |
|
147 | - } |
|
136 | + /** |
|
137 | + * @param string $key |
|
138 | + * @return bool|mixed |
|
139 | + * @throws \OC\ForbiddenException |
|
140 | + */ |
|
141 | + public function remove($key) { |
|
142 | + $storage = $this->getStorage(); |
|
143 | + if (!$storage) { |
|
144 | + return false; |
|
145 | + } |
|
146 | + return $storage->unlink($key); |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * @param string $prefix |
|
151 | - * @return bool |
|
152 | - * @throws \OC\ForbiddenException |
|
153 | - */ |
|
154 | - public function clear($prefix = '') { |
|
155 | - $storage = $this->getStorage(); |
|
156 | - if ($storage and $storage->is_dir('/')) { |
|
157 | - $dh = $storage->opendir('/'); |
|
158 | - if (is_resource($dh)) { |
|
159 | - while (($file = readdir($dh)) !== false) { |
|
160 | - if ($file != '.' and $file != '..' and ($prefix === '' || strpos($file, $prefix) === 0)) { |
|
161 | - $storage->unlink('/' . $file); |
|
162 | - } |
|
163 | - } |
|
164 | - } |
|
165 | - } |
|
166 | - return true; |
|
167 | - } |
|
149 | + /** |
|
150 | + * @param string $prefix |
|
151 | + * @return bool |
|
152 | + * @throws \OC\ForbiddenException |
|
153 | + */ |
|
154 | + public function clear($prefix = '') { |
|
155 | + $storage = $this->getStorage(); |
|
156 | + if ($storage and $storage->is_dir('/')) { |
|
157 | + $dh = $storage->opendir('/'); |
|
158 | + if (is_resource($dh)) { |
|
159 | + while (($file = readdir($dh)) !== false) { |
|
160 | + if ($file != '.' and $file != '..' and ($prefix === '' || strpos($file, $prefix) === 0)) { |
|
161 | + $storage->unlink('/' . $file); |
|
162 | + } |
|
163 | + } |
|
164 | + } |
|
165 | + } |
|
166 | + return true; |
|
167 | + } |
|
168 | 168 | |
169 | - /** |
|
170 | - * Runs GC |
|
171 | - * @throws \OC\ForbiddenException |
|
172 | - */ |
|
173 | - public function gc() { |
|
174 | - $storage = $this->getStorage(); |
|
175 | - if ($storage and $storage->is_dir('/')) { |
|
176 | - // extra hour safety, in case of stray part chunks that take longer to write, |
|
177 | - // because touch() is only called after the chunk was finished |
|
178 | - $now = time() - 3600; |
|
179 | - $dh = $storage->opendir('/'); |
|
180 | - if (!is_resource($dh)) { |
|
181 | - return null; |
|
182 | - } |
|
183 | - while (($file = readdir($dh)) !== false) { |
|
184 | - if ($file != '.' and $file != '..') { |
|
185 | - try { |
|
186 | - $mtime = $storage->filemtime('/' . $file); |
|
187 | - if ($mtime < $now) { |
|
188 | - $storage->unlink('/' . $file); |
|
189 | - } |
|
190 | - } catch (\OCP\Lock\LockedException $e) { |
|
191 | - // ignore locked chunks |
|
192 | - \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core')); |
|
193 | - } catch (\OCP\Files\ForbiddenException $e) { |
|
194 | - \OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "' . $file . '"', array('app' => 'core')); |
|
195 | - } catch (\OCP\Files\LockNotAcquiredException $e) { |
|
196 | - \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core')); |
|
197 | - } |
|
198 | - } |
|
199 | - } |
|
200 | - } |
|
201 | - } |
|
169 | + /** |
|
170 | + * Runs GC |
|
171 | + * @throws \OC\ForbiddenException |
|
172 | + */ |
|
173 | + public function gc() { |
|
174 | + $storage = $this->getStorage(); |
|
175 | + if ($storage and $storage->is_dir('/')) { |
|
176 | + // extra hour safety, in case of stray part chunks that take longer to write, |
|
177 | + // because touch() is only called after the chunk was finished |
|
178 | + $now = time() - 3600; |
|
179 | + $dh = $storage->opendir('/'); |
|
180 | + if (!is_resource($dh)) { |
|
181 | + return null; |
|
182 | + } |
|
183 | + while (($file = readdir($dh)) !== false) { |
|
184 | + if ($file != '.' and $file != '..') { |
|
185 | + try { |
|
186 | + $mtime = $storage->filemtime('/' . $file); |
|
187 | + if ($mtime < $now) { |
|
188 | + $storage->unlink('/' . $file); |
|
189 | + } |
|
190 | + } catch (\OCP\Lock\LockedException $e) { |
|
191 | + // ignore locked chunks |
|
192 | + \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core')); |
|
193 | + } catch (\OCP\Files\ForbiddenException $e) { |
|
194 | + \OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "' . $file . '"', array('app' => 'core')); |
|
195 | + } catch (\OCP\Files\LockNotAcquiredException $e) { |
|
196 | + \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core')); |
|
197 | + } |
|
198 | + } |
|
199 | + } |
|
200 | + } |
|
201 | + } |
|
202 | 202 | } |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | $rootView = new View(); |
52 | 52 | $user = \OC::$server->getUserSession()->getUser(); |
53 | 53 | Filesystem::initMountPoints($user->getUID()); |
54 | - if (!$rootView->file_exists('/' . $user->getUID() . '/cache')) { |
|
55 | - $rootView->mkdir('/' . $user->getUID() . '/cache'); |
|
54 | + if (!$rootView->file_exists('/'.$user->getUID().'/cache')) { |
|
55 | + $rootView->mkdir('/'.$user->getUID().'/cache'); |
|
56 | 56 | } |
57 | - $this->storage = new View('/' . $user->getUID() . '/cache'); |
|
57 | + $this->storage = new View('/'.$user->getUID().'/cache'); |
|
58 | 58 | return $this->storage; |
59 | 59 | } else { |
60 | 60 | \OCP\Util::writeLog('core', 'Can\'t get cache storage, user not logged in', \OCP\Util::ERROR); |
@@ -104,12 +104,12 @@ discard block |
||
104 | 104 | // unique id to avoid chunk collision, just in case |
105 | 105 | $uniqueId = \OC::$server->getSecureRandom()->generate( |
106 | 106 | 16, |
107 | - ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER |
|
107 | + ISecureRandom::CHAR_DIGITS.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER |
|
108 | 108 | ); |
109 | 109 | |
110 | 110 | // use part file to prevent hasKey() to find the key |
111 | 111 | // while it is being written |
112 | - $keyPart = $key . '.' . $uniqueId . '.part'; |
|
112 | + $keyPart = $key.'.'.$uniqueId.'.part'; |
|
113 | 113 | if ($storage and $storage->file_put_contents($keyPart, $value)) { |
114 | 114 | if ($ttl === 0) { |
115 | 115 | $ttl = 86400; // 60*60*24 |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | if (is_resource($dh)) { |
159 | 159 | while (($file = readdir($dh)) !== false) { |
160 | 160 | if ($file != '.' and $file != '..' and ($prefix === '' || strpos($file, $prefix) === 0)) { |
161 | - $storage->unlink('/' . $file); |
|
161 | + $storage->unlink('/'.$file); |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | } |
@@ -183,17 +183,17 @@ discard block |
||
183 | 183 | while (($file = readdir($dh)) !== false) { |
184 | 184 | if ($file != '.' and $file != '..') { |
185 | 185 | try { |
186 | - $mtime = $storage->filemtime('/' . $file); |
|
186 | + $mtime = $storage->filemtime('/'.$file); |
|
187 | 187 | if ($mtime < $now) { |
188 | - $storage->unlink('/' . $file); |
|
188 | + $storage->unlink('/'.$file); |
|
189 | 189 | } |
190 | 190 | } catch (\OCP\Lock\LockedException $e) { |
191 | 191 | // ignore locked chunks |
192 | - \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core')); |
|
192 | + \OC::$server->getLogger()->debug('Could not cleanup locked chunk "'.$file.'"', array('app' => 'core')); |
|
193 | 193 | } catch (\OCP\Files\ForbiddenException $e) { |
194 | - \OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "' . $file . '"', array('app' => 'core')); |
|
194 | + \OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "'.$file.'"', array('app' => 'core')); |
|
195 | 195 | } catch (\OCP\Files\LockNotAcquiredException $e) { |
196 | - \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core')); |
|
196 | + \OC::$server->getLogger()->debug('Could not cleanup locked chunk "'.$file.'"', array('app' => 'core')); |
|
197 | 197 | } |
198 | 198 | } |
199 | 199 | } |
@@ -26,19 +26,19 @@ |
||
26 | 26 | */ |
27 | 27 | interface RepairStep { |
28 | 28 | |
29 | - /** |
|
30 | - * Returns the step's name |
|
31 | - * |
|
32 | - * @return string |
|
33 | - */ |
|
34 | - public function getName(); |
|
29 | + /** |
|
30 | + * Returns the step's name |
|
31 | + * |
|
32 | + * @return string |
|
33 | + */ |
|
34 | + public function getName(); |
|
35 | 35 | |
36 | - /** |
|
37 | - * Run repair step. |
|
38 | - * Must throw exception on error. |
|
39 | - * |
|
40 | - * @throws \Exception in case of failure |
|
41 | - */ |
|
42 | - public function run(); |
|
36 | + /** |
|
37 | + * Run repair step. |
|
38 | + * Must throw exception on error. |
|
39 | + * |
|
40 | + * @throws \Exception in case of failure |
|
41 | + */ |
|
42 | + public function run(); |
|
43 | 43 | |
44 | 44 | } |
@@ -23,32 +23,32 @@ |
||
23 | 23 | namespace OC\Memcache; |
24 | 24 | |
25 | 25 | trait CADTrait { |
26 | - abstract public function get($key); |
|
26 | + abstract public function get($key); |
|
27 | 27 | |
28 | - abstract public function remove($key); |
|
28 | + abstract public function remove($key); |
|
29 | 29 | |
30 | - abstract public function add($key, $value, $ttl = 0); |
|
30 | + abstract public function add($key, $value, $ttl = 0); |
|
31 | 31 | |
32 | - /** |
|
33 | - * Compare and delete |
|
34 | - * |
|
35 | - * @param string $key |
|
36 | - * @param mixed $old |
|
37 | - * @return bool |
|
38 | - */ |
|
39 | - public function cad($key, $old) { |
|
40 | - //no native cas, emulate with locking |
|
41 | - if ($this->add($key . '_lock', true)) { |
|
42 | - if ($this->get($key) === $old) { |
|
43 | - $this->remove($key); |
|
44 | - $this->remove($key . '_lock'); |
|
45 | - return true; |
|
46 | - } else { |
|
47 | - $this->remove($key . '_lock'); |
|
48 | - return false; |
|
49 | - } |
|
50 | - } else { |
|
51 | - return false; |
|
52 | - } |
|
53 | - } |
|
32 | + /** |
|
33 | + * Compare and delete |
|
34 | + * |
|
35 | + * @param string $key |
|
36 | + * @param mixed $old |
|
37 | + * @return bool |
|
38 | + */ |
|
39 | + public function cad($key, $old) { |
|
40 | + //no native cas, emulate with locking |
|
41 | + if ($this->add($key . '_lock', true)) { |
|
42 | + if ($this->get($key) === $old) { |
|
43 | + $this->remove($key); |
|
44 | + $this->remove($key . '_lock'); |
|
45 | + return true; |
|
46 | + } else { |
|
47 | + $this->remove($key . '_lock'); |
|
48 | + return false; |
|
49 | + } |
|
50 | + } else { |
|
51 | + return false; |
|
52 | + } |
|
53 | + } |
|
54 | 54 | } |
@@ -38,13 +38,13 @@ |
||
38 | 38 | */ |
39 | 39 | public function cad($key, $old) { |
40 | 40 | //no native cas, emulate with locking |
41 | - if ($this->add($key . '_lock', true)) { |
|
41 | + if ($this->add($key.'_lock', true)) { |
|
42 | 42 | if ($this->get($key) === $old) { |
43 | 43 | $this->remove($key); |
44 | - $this->remove($key . '_lock'); |
|
44 | + $this->remove($key.'_lock'); |
|
45 | 45 | return true; |
46 | 46 | } else { |
47 | - $this->remove($key . '_lock'); |
|
47 | + $this->remove($key.'_lock'); |
|
48 | 48 | return false; |
49 | 49 | } |
50 | 50 | } else { |
@@ -35,102 +35,102 @@ |
||
35 | 35 | * functions etc. |
36 | 36 | */ |
37 | 37 | class XCache extends Cache implements IMemcache { |
38 | - use CASTrait; |
|
38 | + use CASTrait; |
|
39 | 39 | |
40 | - use CADTrait; |
|
40 | + use CADTrait; |
|
41 | 41 | |
42 | - /** |
|
43 | - * entries in XCache gets namespaced to prevent collisions between ownCloud instances and users |
|
44 | - */ |
|
45 | - protected function getNameSpace() { |
|
46 | - return $this->prefix; |
|
47 | - } |
|
42 | + /** |
|
43 | + * entries in XCache gets namespaced to prevent collisions between ownCloud instances and users |
|
44 | + */ |
|
45 | + protected function getNameSpace() { |
|
46 | + return $this->prefix; |
|
47 | + } |
|
48 | 48 | |
49 | - public function get($key) { |
|
50 | - return xcache_get($this->getNamespace() . $key); |
|
51 | - } |
|
49 | + public function get($key) { |
|
50 | + return xcache_get($this->getNamespace() . $key); |
|
51 | + } |
|
52 | 52 | |
53 | - public function set($key, $value, $ttl = 0) { |
|
54 | - if ($ttl > 0) { |
|
55 | - return xcache_set($this->getNamespace() . $key, $value, $ttl); |
|
56 | - } else { |
|
57 | - return xcache_set($this->getNamespace() . $key, $value); |
|
58 | - } |
|
59 | - } |
|
53 | + public function set($key, $value, $ttl = 0) { |
|
54 | + if ($ttl > 0) { |
|
55 | + return xcache_set($this->getNamespace() . $key, $value, $ttl); |
|
56 | + } else { |
|
57 | + return xcache_set($this->getNamespace() . $key, $value); |
|
58 | + } |
|
59 | + } |
|
60 | 60 | |
61 | - public function hasKey($key) { |
|
62 | - return xcache_isset($this->getNamespace() . $key); |
|
63 | - } |
|
61 | + public function hasKey($key) { |
|
62 | + return xcache_isset($this->getNamespace() . $key); |
|
63 | + } |
|
64 | 64 | |
65 | - public function remove($key) { |
|
66 | - return xcache_unset($this->getNamespace() . $key); |
|
67 | - } |
|
65 | + public function remove($key) { |
|
66 | + return xcache_unset($this->getNamespace() . $key); |
|
67 | + } |
|
68 | 68 | |
69 | - public function clear($prefix = '') { |
|
70 | - if (function_exists('xcache_unset_by_prefix')) { |
|
71 | - return xcache_unset_by_prefix($this->getNamespace() . $prefix); |
|
72 | - } else { |
|
73 | - // Since we can not clear by prefix, we just clear the whole cache. |
|
74 | - xcache_clear_cache(\XC_TYPE_VAR, 0); |
|
75 | - } |
|
76 | - return true; |
|
77 | - } |
|
69 | + public function clear($prefix = '') { |
|
70 | + if (function_exists('xcache_unset_by_prefix')) { |
|
71 | + return xcache_unset_by_prefix($this->getNamespace() . $prefix); |
|
72 | + } else { |
|
73 | + // Since we can not clear by prefix, we just clear the whole cache. |
|
74 | + xcache_clear_cache(\XC_TYPE_VAR, 0); |
|
75 | + } |
|
76 | + return true; |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Set a value in the cache if it's not already stored |
|
81 | - * |
|
82 | - * @param string $key |
|
83 | - * @param mixed $value |
|
84 | - * @param int $ttl Time To Live in seconds. Defaults to 60*60*24 |
|
85 | - * @return bool |
|
86 | - */ |
|
87 | - public function add($key, $value, $ttl = 0) { |
|
88 | - if ($this->hasKey($key)) { |
|
89 | - return false; |
|
90 | - } else { |
|
91 | - return $this->set($key, $value, $ttl); |
|
92 | - } |
|
93 | - } |
|
79 | + /** |
|
80 | + * Set a value in the cache if it's not already stored |
|
81 | + * |
|
82 | + * @param string $key |
|
83 | + * @param mixed $value |
|
84 | + * @param int $ttl Time To Live in seconds. Defaults to 60*60*24 |
|
85 | + * @return bool |
|
86 | + */ |
|
87 | + public function add($key, $value, $ttl = 0) { |
|
88 | + if ($this->hasKey($key)) { |
|
89 | + return false; |
|
90 | + } else { |
|
91 | + return $this->set($key, $value, $ttl); |
|
92 | + } |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Increase a stored number |
|
97 | - * |
|
98 | - * @param string $key |
|
99 | - * @param int $step |
|
100 | - * @return int | bool |
|
101 | - */ |
|
102 | - public function inc($key, $step = 1) { |
|
103 | - return xcache_inc($this->getPrefix() . $key, $step); |
|
104 | - } |
|
95 | + /** |
|
96 | + * Increase a stored number |
|
97 | + * |
|
98 | + * @param string $key |
|
99 | + * @param int $step |
|
100 | + * @return int | bool |
|
101 | + */ |
|
102 | + public function inc($key, $step = 1) { |
|
103 | + return xcache_inc($this->getPrefix() . $key, $step); |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * Decrease a stored number |
|
108 | - * |
|
109 | - * @param string $key |
|
110 | - * @param int $step |
|
111 | - * @return int | bool |
|
112 | - */ |
|
113 | - public function dec($key, $step = 1) { |
|
114 | - return xcache_dec($this->getPrefix() . $key, $step); |
|
115 | - } |
|
106 | + /** |
|
107 | + * Decrease a stored number |
|
108 | + * |
|
109 | + * @param string $key |
|
110 | + * @param int $step |
|
111 | + * @return int | bool |
|
112 | + */ |
|
113 | + public function dec($key, $step = 1) { |
|
114 | + return xcache_dec($this->getPrefix() . $key, $step); |
|
115 | + } |
|
116 | 116 | |
117 | - static public function isAvailable() { |
|
118 | - if (!extension_loaded('xcache')) { |
|
119 | - return false; |
|
120 | - } |
|
121 | - if (\OC::$CLI && !getenv('XCACHE_TEST')) { |
|
122 | - return false; |
|
123 | - } |
|
124 | - if (!function_exists('xcache_unset_by_prefix') && \OC::$server->getIniWrapper()->getBool('xcache.admin.enable_auth')) { |
|
125 | - // We do not want to use XCache if we can not clear it without |
|
126 | - // using the administration function xcache_clear_cache() |
|
127 | - // AND administration functions are password-protected. |
|
128 | - return false; |
|
129 | - } |
|
130 | - $var_size = \OC::$server->getIniWrapper()->getBytes('xcache.var_size'); |
|
131 | - if (!$var_size) { |
|
132 | - return false; |
|
133 | - } |
|
134 | - return true; |
|
135 | - } |
|
117 | + static public function isAvailable() { |
|
118 | + if (!extension_loaded('xcache')) { |
|
119 | + return false; |
|
120 | + } |
|
121 | + if (\OC::$CLI && !getenv('XCACHE_TEST')) { |
|
122 | + return false; |
|
123 | + } |
|
124 | + if (!function_exists('xcache_unset_by_prefix') && \OC::$server->getIniWrapper()->getBool('xcache.admin.enable_auth')) { |
|
125 | + // We do not want to use XCache if we can not clear it without |
|
126 | + // using the administration function xcache_clear_cache() |
|
127 | + // AND administration functions are password-protected. |
|
128 | + return false; |
|
129 | + } |
|
130 | + $var_size = \OC::$server->getIniWrapper()->getBytes('xcache.var_size'); |
|
131 | + if (!$var_size) { |
|
132 | + return false; |
|
133 | + } |
|
134 | + return true; |
|
135 | + } |
|
136 | 136 | } |
@@ -47,28 +47,28 @@ discard block |
||
47 | 47 | } |
48 | 48 | |
49 | 49 | public function get($key) { |
50 | - return xcache_get($this->getNamespace() . $key); |
|
50 | + return xcache_get($this->getNamespace().$key); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | public function set($key, $value, $ttl = 0) { |
54 | 54 | if ($ttl > 0) { |
55 | - return xcache_set($this->getNamespace() . $key, $value, $ttl); |
|
55 | + return xcache_set($this->getNamespace().$key, $value, $ttl); |
|
56 | 56 | } else { |
57 | - return xcache_set($this->getNamespace() . $key, $value); |
|
57 | + return xcache_set($this->getNamespace().$key, $value); |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
61 | 61 | public function hasKey($key) { |
62 | - return xcache_isset($this->getNamespace() . $key); |
|
62 | + return xcache_isset($this->getNamespace().$key); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | public function remove($key) { |
66 | - return xcache_unset($this->getNamespace() . $key); |
|
66 | + return xcache_unset($this->getNamespace().$key); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | public function clear($prefix = '') { |
70 | 70 | if (function_exists('xcache_unset_by_prefix')) { |
71 | - return xcache_unset_by_prefix($this->getNamespace() . $prefix); |
|
71 | + return xcache_unset_by_prefix($this->getNamespace().$prefix); |
|
72 | 72 | } else { |
73 | 73 | // Since we can not clear by prefix, we just clear the whole cache. |
74 | 74 | xcache_clear_cache(\XC_TYPE_VAR, 0); |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | * @return int | bool |
101 | 101 | */ |
102 | 102 | public function inc($key, $step = 1) { |
103 | - return xcache_inc($this->getPrefix() . $key, $step); |
|
103 | + return xcache_inc($this->getPrefix().$key, $step); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @return int | bool |
112 | 112 | */ |
113 | 113 | public function dec($key, $step = 1) { |
114 | - return xcache_dec($this->getPrefix() . $key, $step); |
|
114 | + return xcache_dec($this->getPrefix().$key, $step); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | static public function isAvailable() { |
@@ -26,72 +26,72 @@ |
||
26 | 26 | namespace OC\Memcache; |
27 | 27 | |
28 | 28 | abstract class Cache implements \ArrayAccess, \OCP\ICache { |
29 | - /** |
|
30 | - * @var string $prefix |
|
31 | - */ |
|
32 | - protected $prefix; |
|
29 | + /** |
|
30 | + * @var string $prefix |
|
31 | + */ |
|
32 | + protected $prefix; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param string $prefix |
|
36 | - */ |
|
37 | - public function __construct($prefix = '') { |
|
38 | - $this->prefix = $prefix; |
|
39 | - } |
|
34 | + /** |
|
35 | + * @param string $prefix |
|
36 | + */ |
|
37 | + public function __construct($prefix = '') { |
|
38 | + $this->prefix = $prefix; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @return string Prefix used for caching purposes |
|
43 | - */ |
|
44 | - public function getPrefix() { |
|
45 | - return $this->prefix; |
|
46 | - } |
|
41 | + /** |
|
42 | + * @return string Prefix used for caching purposes |
|
43 | + */ |
|
44 | + public function getPrefix() { |
|
45 | + return $this->prefix; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param string $key |
|
50 | - * @return mixed |
|
51 | - */ |
|
52 | - abstract public function get($key); |
|
48 | + /** |
|
49 | + * @param string $key |
|
50 | + * @return mixed |
|
51 | + */ |
|
52 | + abstract public function get($key); |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param string $key |
|
56 | - * @param mixed $value |
|
57 | - * @param int $ttl |
|
58 | - * @return mixed |
|
59 | - */ |
|
60 | - abstract public function set($key, $value, $ttl = 0); |
|
54 | + /** |
|
55 | + * @param string $key |
|
56 | + * @param mixed $value |
|
57 | + * @param int $ttl |
|
58 | + * @return mixed |
|
59 | + */ |
|
60 | + abstract public function set($key, $value, $ttl = 0); |
|
61 | 61 | |
62 | - /** |
|
63 | - * @param string $key |
|
64 | - * @return mixed |
|
65 | - */ |
|
66 | - abstract public function hasKey($key); |
|
62 | + /** |
|
63 | + * @param string $key |
|
64 | + * @return mixed |
|
65 | + */ |
|
66 | + abstract public function hasKey($key); |
|
67 | 67 | |
68 | - /** |
|
69 | - * @param string $key |
|
70 | - * @return mixed |
|
71 | - */ |
|
72 | - abstract public function remove($key); |
|
68 | + /** |
|
69 | + * @param string $key |
|
70 | + * @return mixed |
|
71 | + */ |
|
72 | + abstract public function remove($key); |
|
73 | 73 | |
74 | - /** |
|
75 | - * @param string $prefix |
|
76 | - * @return mixed |
|
77 | - */ |
|
78 | - abstract public function clear($prefix = ''); |
|
74 | + /** |
|
75 | + * @param string $prefix |
|
76 | + * @return mixed |
|
77 | + */ |
|
78 | + abstract public function clear($prefix = ''); |
|
79 | 79 | |
80 | - //implement the ArrayAccess interface |
|
80 | + //implement the ArrayAccess interface |
|
81 | 81 | |
82 | - public function offsetExists($offset) { |
|
83 | - return $this->hasKey($offset); |
|
84 | - } |
|
82 | + public function offsetExists($offset) { |
|
83 | + return $this->hasKey($offset); |
|
84 | + } |
|
85 | 85 | |
86 | - public function offsetSet($offset, $value) { |
|
87 | - $this->set($offset, $value); |
|
88 | - } |
|
86 | + public function offsetSet($offset, $value) { |
|
87 | + $this->set($offset, $value); |
|
88 | + } |
|
89 | 89 | |
90 | - public function offsetGet($offset) { |
|
91 | - return $this->get($offset); |
|
92 | - } |
|
90 | + public function offsetGet($offset) { |
|
91 | + return $this->get($offset); |
|
92 | + } |
|
93 | 93 | |
94 | - public function offsetUnset($offset) { |
|
95 | - $this->remove($offset); |
|
96 | - } |
|
94 | + public function offsetUnset($offset) { |
|
95 | + $this->remove($offset); |
|
96 | + } |
|
97 | 97 | } |
@@ -33,158 +33,158 @@ |
||
33 | 33 | use \OCP\ILogger; |
34 | 34 | |
35 | 35 | class Factory implements ICacheFactory { |
36 | - const NULL_CACHE = '\\OC\\Memcache\\NullCache'; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var string $globalPrefix |
|
40 | - */ |
|
41 | - private $globalPrefix; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var ILogger $logger |
|
45 | - */ |
|
46 | - private $logger; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var string $localCacheClass |
|
50 | - */ |
|
51 | - private $localCacheClass; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var string $distributedCacheClass |
|
55 | - */ |
|
56 | - private $distributedCacheClass; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var string $lockingCacheClass |
|
60 | - */ |
|
61 | - private $lockingCacheClass; |
|
62 | - |
|
63 | - /** |
|
64 | - * @param string $globalPrefix |
|
65 | - * @param ILogger $logger |
|
66 | - * @param string|null $localCacheClass |
|
67 | - * @param string|null $distributedCacheClass |
|
68 | - * @param string|null $lockingCacheClass |
|
69 | - */ |
|
70 | - public function __construct($globalPrefix, ILogger $logger, |
|
71 | - $localCacheClass = null, $distributedCacheClass = null, $lockingCacheClass = null) |
|
72 | - { |
|
73 | - $this->logger = $logger; |
|
74 | - $this->globalPrefix = $globalPrefix; |
|
75 | - |
|
76 | - if (!$localCacheClass) { |
|
77 | - $localCacheClass = self::NULL_CACHE; |
|
78 | - } |
|
79 | - if (!$distributedCacheClass) { |
|
80 | - $distributedCacheClass = $localCacheClass; |
|
81 | - } |
|
82 | - |
|
83 | - $missingCacheMessage = 'Memcache {class} not available for {use} cache'; |
|
84 | - $missingCacheHint = 'Is the matching PHP module installed and enabled?'; |
|
85 | - if (!$localCacheClass::isAvailable()) { |
|
86 | - if (\OC::$CLI && !defined('PHPUNIT_RUN')) { |
|
87 | - // CLI should not hard-fail on broken memcache |
|
88 | - $this->logger->info($missingCacheMessage, [ |
|
89 | - 'class' => $localCacheClass, |
|
90 | - 'use' => 'local', |
|
91 | - 'app' => 'cli' |
|
92 | - ]); |
|
93 | - $localCacheClass = self::NULL_CACHE; |
|
94 | - } else { |
|
95 | - throw new \OC\HintException(strtr($missingCacheMessage, [ |
|
96 | - '{class}' => $localCacheClass, '{use}' => 'local' |
|
97 | - ]), $missingCacheHint); |
|
98 | - } |
|
99 | - } |
|
100 | - if (!$distributedCacheClass::isAvailable()) { |
|
101 | - if (\OC::$CLI && !defined('PHPUNIT_RUN')) { |
|
102 | - // CLI should not hard-fail on broken memcache |
|
103 | - $this->logger->info($missingCacheMessage, [ |
|
104 | - 'class' => $distributedCacheClass, |
|
105 | - 'use' => 'distributed', |
|
106 | - 'app' => 'cli' |
|
107 | - ]); |
|
108 | - $distributedCacheClass = self::NULL_CACHE; |
|
109 | - } else { |
|
110 | - throw new \OC\HintException(strtr($missingCacheMessage, [ |
|
111 | - '{class}' => $distributedCacheClass, '{use}' => 'distributed' |
|
112 | - ]), $missingCacheHint); |
|
113 | - } |
|
114 | - } |
|
115 | - if (!($lockingCacheClass && $lockingCacheClass::isAvailable())) { |
|
116 | - // dont fallback since the fallback might not be suitable for storing lock |
|
117 | - $lockingCacheClass = self::NULL_CACHE; |
|
118 | - } |
|
119 | - |
|
120 | - $this->localCacheClass = $localCacheClass; |
|
121 | - $this->distributedCacheClass = $distributedCacheClass; |
|
122 | - $this->lockingCacheClass = $lockingCacheClass; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * create a cache instance for storing locks |
|
127 | - * |
|
128 | - * @param string $prefix |
|
129 | - * @return \OCP\IMemcache |
|
130 | - */ |
|
131 | - public function createLocking($prefix = '') { |
|
132 | - return new $this->lockingCacheClass($this->globalPrefix . '/' . $prefix); |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * create a distributed cache instance |
|
137 | - * |
|
138 | - * @param string $prefix |
|
139 | - * @return \OC\Memcache\Cache |
|
140 | - */ |
|
141 | - public function createDistributed($prefix = '') { |
|
142 | - return new $this->distributedCacheClass($this->globalPrefix . '/' . $prefix); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * create a local cache instance |
|
147 | - * |
|
148 | - * @param string $prefix |
|
149 | - * @return \OC\Memcache\Cache |
|
150 | - */ |
|
151 | - public function createLocal($prefix = '') { |
|
152 | - return new $this->localCacheClass($this->globalPrefix . '/' . $prefix); |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * @see \OC\Memcache\Factory::createDistributed() |
|
157 | - * @param string $prefix |
|
158 | - * @return \OC\Memcache\Cache |
|
159 | - */ |
|
160 | - public function create($prefix = '') { |
|
161 | - return $this->createDistributed($prefix); |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * check memcache availability |
|
166 | - * |
|
167 | - * @return bool |
|
168 | - */ |
|
169 | - public function isAvailable() { |
|
170 | - return ($this->distributedCacheClass !== self::NULL_CACHE); |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * @see \OC\Memcache\Factory::createLocal() |
|
175 | - * @param string $prefix |
|
176 | - * @return Cache |
|
177 | - */ |
|
178 | - public function createLowLatency($prefix = '') { |
|
179 | - return $this->createLocal($prefix); |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * check local memcache availability |
|
184 | - * |
|
185 | - * @return bool |
|
186 | - */ |
|
187 | - public function isAvailableLowLatency() { |
|
188 | - return ($this->localCacheClass !== self::NULL_CACHE); |
|
189 | - } |
|
36 | + const NULL_CACHE = '\\OC\\Memcache\\NullCache'; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var string $globalPrefix |
|
40 | + */ |
|
41 | + private $globalPrefix; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var ILogger $logger |
|
45 | + */ |
|
46 | + private $logger; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var string $localCacheClass |
|
50 | + */ |
|
51 | + private $localCacheClass; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var string $distributedCacheClass |
|
55 | + */ |
|
56 | + private $distributedCacheClass; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var string $lockingCacheClass |
|
60 | + */ |
|
61 | + private $lockingCacheClass; |
|
62 | + |
|
63 | + /** |
|
64 | + * @param string $globalPrefix |
|
65 | + * @param ILogger $logger |
|
66 | + * @param string|null $localCacheClass |
|
67 | + * @param string|null $distributedCacheClass |
|
68 | + * @param string|null $lockingCacheClass |
|
69 | + */ |
|
70 | + public function __construct($globalPrefix, ILogger $logger, |
|
71 | + $localCacheClass = null, $distributedCacheClass = null, $lockingCacheClass = null) |
|
72 | + { |
|
73 | + $this->logger = $logger; |
|
74 | + $this->globalPrefix = $globalPrefix; |
|
75 | + |
|
76 | + if (!$localCacheClass) { |
|
77 | + $localCacheClass = self::NULL_CACHE; |
|
78 | + } |
|
79 | + if (!$distributedCacheClass) { |
|
80 | + $distributedCacheClass = $localCacheClass; |
|
81 | + } |
|
82 | + |
|
83 | + $missingCacheMessage = 'Memcache {class} not available for {use} cache'; |
|
84 | + $missingCacheHint = 'Is the matching PHP module installed and enabled?'; |
|
85 | + if (!$localCacheClass::isAvailable()) { |
|
86 | + if (\OC::$CLI && !defined('PHPUNIT_RUN')) { |
|
87 | + // CLI should not hard-fail on broken memcache |
|
88 | + $this->logger->info($missingCacheMessage, [ |
|
89 | + 'class' => $localCacheClass, |
|
90 | + 'use' => 'local', |
|
91 | + 'app' => 'cli' |
|
92 | + ]); |
|
93 | + $localCacheClass = self::NULL_CACHE; |
|
94 | + } else { |
|
95 | + throw new \OC\HintException(strtr($missingCacheMessage, [ |
|
96 | + '{class}' => $localCacheClass, '{use}' => 'local' |
|
97 | + ]), $missingCacheHint); |
|
98 | + } |
|
99 | + } |
|
100 | + if (!$distributedCacheClass::isAvailable()) { |
|
101 | + if (\OC::$CLI && !defined('PHPUNIT_RUN')) { |
|
102 | + // CLI should not hard-fail on broken memcache |
|
103 | + $this->logger->info($missingCacheMessage, [ |
|
104 | + 'class' => $distributedCacheClass, |
|
105 | + 'use' => 'distributed', |
|
106 | + 'app' => 'cli' |
|
107 | + ]); |
|
108 | + $distributedCacheClass = self::NULL_CACHE; |
|
109 | + } else { |
|
110 | + throw new \OC\HintException(strtr($missingCacheMessage, [ |
|
111 | + '{class}' => $distributedCacheClass, '{use}' => 'distributed' |
|
112 | + ]), $missingCacheHint); |
|
113 | + } |
|
114 | + } |
|
115 | + if (!($lockingCacheClass && $lockingCacheClass::isAvailable())) { |
|
116 | + // dont fallback since the fallback might not be suitable for storing lock |
|
117 | + $lockingCacheClass = self::NULL_CACHE; |
|
118 | + } |
|
119 | + |
|
120 | + $this->localCacheClass = $localCacheClass; |
|
121 | + $this->distributedCacheClass = $distributedCacheClass; |
|
122 | + $this->lockingCacheClass = $lockingCacheClass; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * create a cache instance for storing locks |
|
127 | + * |
|
128 | + * @param string $prefix |
|
129 | + * @return \OCP\IMemcache |
|
130 | + */ |
|
131 | + public function createLocking($prefix = '') { |
|
132 | + return new $this->lockingCacheClass($this->globalPrefix . '/' . $prefix); |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * create a distributed cache instance |
|
137 | + * |
|
138 | + * @param string $prefix |
|
139 | + * @return \OC\Memcache\Cache |
|
140 | + */ |
|
141 | + public function createDistributed($prefix = '') { |
|
142 | + return new $this->distributedCacheClass($this->globalPrefix . '/' . $prefix); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * create a local cache instance |
|
147 | + * |
|
148 | + * @param string $prefix |
|
149 | + * @return \OC\Memcache\Cache |
|
150 | + */ |
|
151 | + public function createLocal($prefix = '') { |
|
152 | + return new $this->localCacheClass($this->globalPrefix . '/' . $prefix); |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * @see \OC\Memcache\Factory::createDistributed() |
|
157 | + * @param string $prefix |
|
158 | + * @return \OC\Memcache\Cache |
|
159 | + */ |
|
160 | + public function create($prefix = '') { |
|
161 | + return $this->createDistributed($prefix); |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * check memcache availability |
|
166 | + * |
|
167 | + * @return bool |
|
168 | + */ |
|
169 | + public function isAvailable() { |
|
170 | + return ($this->distributedCacheClass !== self::NULL_CACHE); |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * @see \OC\Memcache\Factory::createLocal() |
|
175 | + * @param string $prefix |
|
176 | + * @return Cache |
|
177 | + */ |
|
178 | + public function createLowLatency($prefix = '') { |
|
179 | + return $this->createLocal($prefix); |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * check local memcache availability |
|
184 | + * |
|
185 | + * @return bool |
|
186 | + */ |
|
187 | + public function isAvailableLowLatency() { |
|
188 | + return ($this->localCacheClass !== self::NULL_CACHE); |
|
189 | + } |
|
190 | 190 | } |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | * @return \OCP\IMemcache |
131 | 131 | */ |
132 | 132 | public function createLocking($prefix = '') { |
133 | - return new $this->lockingCacheClass($this->globalPrefix . '/' . $prefix); |
|
133 | + return new $this->lockingCacheClass($this->globalPrefix.'/'.$prefix); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * @return \OC\Memcache\Cache |
141 | 141 | */ |
142 | 142 | public function createDistributed($prefix = '') { |
143 | - return new $this->distributedCacheClass($this->globalPrefix . '/' . $prefix); |
|
143 | + return new $this->distributedCacheClass($this->globalPrefix.'/'.$prefix); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | * @return \OC\Memcache\Cache |
151 | 151 | */ |
152 | 152 | public function createLocal($prefix = '') { |
153 | - return new $this->localCacheClass($this->globalPrefix . '/' . $prefix); |
|
153 | + return new $this->localCacheClass($this->globalPrefix.'/'.$prefix); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |