From c2cccfe396bb10c8d2784de2b62d50c0f702d873 Mon Sep 17 00:00:00 2001 From: Jirka F Date: Fri, 4 Aug 2017 11:57:59 +0200 Subject: [PATCH 01/11] =?UTF-8?q?P=C5=99id=C3=A1n=C3=AD=20maz=C3=A1n=C3=AD?= =?UTF-8?q?=20namespace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Caching/Cache.php | 98 ++++++++++++++---------- src/Caching/Storages/FileStorage.php | 100 ++++++++++++++++--------- src/Caching/Storages/SQLiteStorage.php | 65 ++++++++++------ 3 files changed, 163 insertions(+), 100 deletions(-) diff --git a/src/Caching/Cache.php b/src/Caching/Cache.php index 4eb7aa17..cdffb21c 100644 --- a/src/Caching/Cache.php +++ b/src/Caching/Cache.php @@ -31,6 +31,7 @@ class Cache ITEMS = 'items', CONSTS = 'consts', CALLBACKS = 'callbacks', + NAMESPACE = 'namespace', ALL = 'all'; /** @internal */ @@ -79,11 +80,12 @@ public function derive(string $namespace) } - /** - * Reads the specified item from the cache or generate it. - * @param mixed - * @return mixed - */ + /** + * Reads the specified item from the cache or generate it. + * @param $key + * @param callable|null $fallback + * @return mixed + */ public function load($key, callable $fallback = null) { $data = $this->storage->read($this->generateKey($key)); @@ -96,9 +98,12 @@ public function load($key, callable $fallback = null) } - /** - * Reads multiple items from the cache. - */ + /** + * Reads multiple items from the cache. + * @param array $keys + * @param callable|null $fallback + * @return array + */ public function bulkLoad(array $keys, callable $fallback = null): array { if (count($keys) === 0) { @@ -142,22 +147,23 @@ public function bulkLoad(array $keys, callable $fallback = null): array } - /** - * Writes item into the cache. - * Dependencies are: - * - Cache::PRIORITY => (int) priority - * - Cache::EXPIRATION => (timestamp) expiration - * - Cache::SLIDING => (bool) use sliding expiration? - * - Cache::TAGS => (array) tags - * - Cache::FILES => (array|string) file names - * - Cache::ITEMS => (array|string) cache items - * - Cache::CONSTS => (array|string) cache items - * - * @param mixed - * @param mixed - * @return mixed value itself - * @throws Nette\InvalidArgumentException - */ + /** + * Writes item into the cache. + * Dependencies are: + * - Cache::PRIORITY => (int) priority + * - Cache::EXPIRATION => (timestamp) expiration + * - Cache::SLIDING => (bool) use sliding expiration? + * - Cache::TAGS => (array) tags + * - Cache::FILES => (array|string) file names + * - Cache::ITEMS => (array|string) cache items + * - Cache::CONSTS => (array|string) cache items + * + * @param $key + * @param $data + * @param array|null $dependencies + * @return mixed value itself + * @throws \Throwable + */ public function save($key, $data, array $dependencies = null) { $key = $this->generateKey($key); @@ -236,13 +242,14 @@ public function remove($key): void } - /** - * Removes items from the cache by conditions. - * Conditions are: - * - Cache::PRIORITY => (int) priority - * - Cache::TAGS => (array) tags - * - Cache::ALL => true - */ + /** + * Removes items from the cache by conditions. + * Conditions are: + * - Cache::PRIORITY => (int) priority + * - Cache::TAGS => (array) tags + * - Cache::ALL => true + * @param array|null $conditions + */ public function clean(array $conditions = null): void { $conditions = (array) $conditions; @@ -270,10 +277,13 @@ public function call($function) } - /** - * Caches results of function/method calls. - * @param mixed - */ + /** + * Caches results of function/method calls. + * @param $function + * @param array|null $dependencies + * @return \Closure + * @internal param $mixed + */ public function wrap($function, array $dependencies = null): \Closure { return function () use ($function, $dependencies) { @@ -331,18 +341,24 @@ public static function checkCallbacks(array $callbacks): bool } - /** - * Checks CONSTS dependency. - */ + /** + * Checks CONSTS dependency. + * @param string $const + * @param $value + * @return bool + */ private static function checkConst(string $const, $value): bool { return defined($const) && constant($const) === $value; } - /** - * Checks FILES dependency. - */ + /** + * Checks FILES dependency. + * @param string $file + * @param int|null $time + * @return bool + */ private static function checkFile(string $file, ?int $time): bool { return @filemtime($file) == $time; // @ - stat may fail diff --git a/src/Caching/Storages/FileStorage.php b/src/Caching/Storages/FileStorage.php index 3205a627..b578b896 100644 --- a/src/Caching/Storages/FileStorage.php +++ b/src/Caching/Storages/FileStorage.php @@ -79,10 +79,11 @@ public function __construct($dir, IJournal $journal = null) } - /** - * Read from cache. - * @return mixed - */ + /** + * Read from cache. + * @param string $key + * @return mixed + */ public function read(string $key) { $meta = $this->readMetaAndLock($this->getCacheFile($key), LOCK_SH); @@ -95,9 +96,11 @@ public function read(string $key) } - /** - * Verifies dependencies. - */ + /** + * Verifies dependencies. + * @param array $meta + * @return bool + */ private function verify(array $meta): bool { do { @@ -133,9 +136,10 @@ private function verify(array $meta): bool } - /** - * Prevents item reading and writing. Lock is released by write() or remove(). - */ + /** + * Prevents item reading and writing. Lock is released by write() or remove(). + * @param string $key + */ public function lock(string $key): void { $cacheFile = $this->getCacheFile($key); @@ -150,9 +154,12 @@ public function lock(string $key): void } - /** - * Writes item into the cache. - */ + /** + * Writes item into the cache. + * @param string $key + * @param $data + * @param array $dp + */ public function write(string $key, $data, array $dp): void { $meta = [ @@ -232,9 +239,10 @@ public function write(string $key, $data, array $dp): void } - /** - * Removes item from the cache. - */ + /** + * Removes item from the cache. + * @param string $key + */ public function remove(string $key): void { unset($this->locks[$key]); @@ -242,13 +250,15 @@ public function remove(string $key): void } - /** - * Removes items from the cache by conditions & garbage collector. - */ + /** + * Removes items from the cache by conditions & garbage collector. + * @param array $conditions + */ public function clean(array $conditions): void { $all = !empty($conditions[Cache::ALL]); $collector = empty($conditions); + $namespaces = $conditions[Cache::NAMESPACE] ?? false; // cleaning using file iterator if ($all || $collector) { @@ -284,6 +294,21 @@ public function clean(array $conditions): void $this->journal->clean($conditions); } return; + } else if($namespaces) { + if (!is_array($namespaces)) { + $namespaces = [$namespaces]; + } + + foreach ($namespaces as $namespace) { + $dir = $this->dir . "/_$namespace"; + if (is_dir($dir)) { + $items = Nette\Utils\Finder::findFiles('')->from($dir); + foreach ($items as $item) { + $this->delete($item); + } + @rmdir($dir); + } + } } // cleaning using journal @@ -295,11 +320,12 @@ public function clean(array $conditions): void } - /** - * Reads cache data from disk. - * @param string file path - * @param int lock mode - */ + /** + * Reads cache data from disk. + * @param string $file path + * @param int $lock mode + * @return array|null + */ protected function readMetaAndLock(string $file, int $lock): ?array { $handle = @fopen($file, 'r+b'); // @ - file may not exist @@ -325,10 +351,11 @@ protected function readMetaAndLock(string $file, int $lock): ?array } - /** - * Reads cache data from disk and closes cache file handle. - * @return mixed - */ + /** + * Reads cache data from disk and closes cache file handle. + * @param array $meta + * @return mixed + */ protected function readData(array $meta) { $data = stream_get_contents($meta[self::HANDLE]); @@ -343,9 +370,11 @@ protected function readData(array $meta) } - /** - * Returns file name. - */ + /** + * Returns file name. + * @param string $key + * @return string + */ protected function getCacheFile(string $key): string { $file = urlencode($key); @@ -356,10 +385,11 @@ protected function getCacheFile(string $key): string } - /** - * Deletes and closes file. - * @param resource $handle - */ + /** + * Deletes and closes file. + * @param string $file + * @param resource $handle + */ private static function delete(string $file, $handle = null): void { if (@unlink($file)) { // @ - file may not already exist diff --git a/src/Caching/Storages/SQLiteStorage.php b/src/Caching/Storages/SQLiteStorage.php index 73cf538d..d59cfd81 100644 --- a/src/Caching/Storages/SQLiteStorage.php +++ b/src/Caching/Storages/SQLiteStorage.php @@ -52,10 +52,11 @@ public function __construct($path) } - /** - * Read from cache. - * @return mixed - */ + /** + * Read from cache. + * @param string $key + * @return mixed + */ public function read(string $key) { $stmt = $this->pdo->prepare('SELECT data, slide FROM cache WHERE key=? AND (expire IS NULL OR expire >= ?)'); @@ -69,10 +70,11 @@ public function read(string $key) } - /** - * Reads from cache in bulk. - * @return array key => value pairs, missing items are omitted - */ + /** + * Reads from cache in bulk. + * @param array $keys + * @return array key => value pairs, missing items are omitted + */ public function bulkRead(array $keys): array { $stmt = $this->pdo->prepare('SELECT key, data, slide FROM cache WHERE key IN (?' . str_repeat(',?', count($keys) - 1) . ') AND (expire IS NULL OR expire >= ?)'); @@ -93,17 +95,21 @@ public function bulkRead(array $keys): array } - /** - * Prevents item reading and writing. Lock is released by write() or remove(). - */ + /** + * Prevents item reading and writing. Lock is released by write() or remove(). + * @param string $key + */ public function lock(string $key): void { } - /** - * Writes item into the cache. - */ + /** + * Writes item into the cache. + * @param string $key + * @param $data + * @param array $dependencies + */ public function write(string $key, $data, array $dependencies): void { $expire = isset($dependencies[Cache::EXPIRATION]) ? $dependencies[Cache::EXPIRATION] + time() : null; @@ -125,9 +131,10 @@ public function write(string $key, $data, array $dependencies): void } - /** - * Removes item from the cache. - */ + /** + * Removes item from the cache. + * @param string $key + */ public function remove(string $key): void { $this->pdo->prepare('DELETE FROM cache WHERE key=?') @@ -135,15 +142,15 @@ public function remove(string $key): void } - /** - * Removes items from the cache by conditions & garbage collector. - */ + /** + * Removes items from the cache by conditions & garbage collector. + * @param array $conditions + */ public function clean(array $conditions): void { if (!empty($conditions[Cache::ALL])) { $this->pdo->prepare('DELETE FROM cache')->execute(); - - } else { + } elseif (!empty($conditions[Cache::TAGS])) { $sql = 'DELETE FROM cache WHERE expire < ?'; $args = [time()]; @@ -153,7 +160,17 @@ public function clean(array $conditions): void $args = array_merge($args, $tags); } - $this->pdo->prepare($sql)->execute($args); - } + $this->pdo->prepare($sql)->execute($args); + } elseif (!empty($conditions[Cache::NAMESPACE])) { + if (is_array($conditions[Cache::NAMESPACE])) { + $namespaces = $conditions[Cache::NAMESPACE]; + } else { + $namespaces = [$conditions[Cache::NAMESPACE]]; + } + + foreach ($namespaces as $namespace) { + $this->pdo->prepare("DELETE FROM cache WHERE key LIKE %/_$namespace/%")->execute(); + } + } } } From 5cdc6fd6892a3ffbc19afbc3312b5ce64d218906 Mon Sep 17 00:00:00 2001 From: aiphee Date: Sat, 5 Aug 2017 14:02:25 +0200 Subject: [PATCH 02/11] Use tabs instead of spaces --- src/Caching/Cache.php | 114 +++++++++++----------- src/Caching/Storages/FileStorage.php | 128 ++++++++++++------------- src/Caching/Storages/SQLiteStorage.php | 80 ++++++++-------- 3 files changed, 161 insertions(+), 161 deletions(-) diff --git a/src/Caching/Cache.php b/src/Caching/Cache.php index cdffb21c..3e36a21b 100644 --- a/src/Caching/Cache.php +++ b/src/Caching/Cache.php @@ -31,7 +31,7 @@ class Cache ITEMS = 'items', CONSTS = 'consts', CALLBACKS = 'callbacks', - NAMESPACE = 'namespace', + NAMESPACE = 'namespace', ALL = 'all'; /** @internal */ @@ -80,12 +80,12 @@ public function derive(string $namespace) } - /** - * Reads the specified item from the cache or generate it. - * @param $key - * @param callable|null $fallback - * @return mixed - */ + /** + * Reads the specified item from the cache or generate it. + * @param $key + * @param callable|null $fallback + * @return mixed + */ public function load($key, callable $fallback = null) { $data = $this->storage->read($this->generateKey($key)); @@ -98,12 +98,12 @@ public function load($key, callable $fallback = null) } - /** - * Reads multiple items from the cache. - * @param array $keys - * @param callable|null $fallback - * @return array - */ + /** + * Reads multiple items from the cache. + * @param array $keys + * @param callable|null $fallback + * @return array + */ public function bulkLoad(array $keys, callable $fallback = null): array { if (count($keys) === 0) { @@ -147,23 +147,23 @@ public function bulkLoad(array $keys, callable $fallback = null): array } - /** - * Writes item into the cache. - * Dependencies are: - * - Cache::PRIORITY => (int) priority - * - Cache::EXPIRATION => (timestamp) expiration - * - Cache::SLIDING => (bool) use sliding expiration? - * - Cache::TAGS => (array) tags - * - Cache::FILES => (array|string) file names - * - Cache::ITEMS => (array|string) cache items - * - Cache::CONSTS => (array|string) cache items - * - * @param $key - * @param $data - * @param array|null $dependencies - * @return mixed value itself - * @throws \Throwable - */ + /** + * Writes item into the cache. + * Dependencies are: + * - Cache::PRIORITY => (int) priority + * - Cache::EXPIRATION => (timestamp) expiration + * - Cache::SLIDING => (bool) use sliding expiration? + * - Cache::TAGS => (array) tags + * - Cache::FILES => (array|string) file names + * - Cache::ITEMS => (array|string) cache items + * - Cache::CONSTS => (array|string) cache items + * + * @param $key + * @param $data + * @param array|null $dependencies + * @return mixed value itself + * @throws \Throwable + */ public function save($key, $data, array $dependencies = null) { $key = $this->generateKey($key); @@ -242,14 +242,14 @@ public function remove($key): void } - /** - * Removes items from the cache by conditions. - * Conditions are: - * - Cache::PRIORITY => (int) priority - * - Cache::TAGS => (array) tags - * - Cache::ALL => true - * @param array|null $conditions - */ + /** + * Removes items from the cache by conditions. + * Conditions are: + * - Cache::PRIORITY => (int) priority + * - Cache::TAGS => (array) tags + * - Cache::ALL => true + * @param array|null $conditions + */ public function clean(array $conditions = null): void { $conditions = (array) $conditions; @@ -277,13 +277,13 @@ public function call($function) } - /** - * Caches results of function/method calls. - * @param $function - * @param array|null $dependencies - * @return \Closure - * @internal param $mixed - */ + /** + * Caches results of function/method calls. + * @param $function + * @param array|null $dependencies + * @return \Closure + * @internal param $mixed + */ public function wrap($function, array $dependencies = null): \Closure { return function () use ($function, $dependencies) { @@ -341,24 +341,24 @@ public static function checkCallbacks(array $callbacks): bool } - /** - * Checks CONSTS dependency. - * @param string $const - * @param $value - * @return bool - */ + /** + * Checks CONSTS dependency. + * @param string $const + * @param $value + * @return bool + */ private static function checkConst(string $const, $value): bool { return defined($const) && constant($const) === $value; } - /** - * Checks FILES dependency. - * @param string $file - * @param int|null $time - * @return bool - */ + /** + * Checks FILES dependency. + * @param string $file + * @param int|null $time + * @return bool + */ private static function checkFile(string $file, ?int $time): bool { return @filemtime($file) == $time; // @ - stat may fail diff --git a/src/Caching/Storages/FileStorage.php b/src/Caching/Storages/FileStorage.php index b578b896..9c8ef794 100644 --- a/src/Caching/Storages/FileStorage.php +++ b/src/Caching/Storages/FileStorage.php @@ -79,11 +79,11 @@ public function __construct($dir, IJournal $journal = null) } - /** - * Read from cache. - * @param string $key - * @return mixed - */ + /** + * Read from cache. + * @param string $key + * @return mixed + */ public function read(string $key) { $meta = $this->readMetaAndLock($this->getCacheFile($key), LOCK_SH); @@ -96,11 +96,11 @@ public function read(string $key) } - /** - * Verifies dependencies. - * @param array $meta - * @return bool - */ + /** + * Verifies dependencies. + * @param array $meta + * @return bool + */ private function verify(array $meta): bool { do { @@ -136,10 +136,10 @@ private function verify(array $meta): bool } - /** - * Prevents item reading and writing. Lock is released by write() or remove(). - * @param string $key - */ + /** + * Prevents item reading and writing. Lock is released by write() or remove(). + * @param string $key + */ public function lock(string $key): void { $cacheFile = $this->getCacheFile($key); @@ -154,12 +154,12 @@ public function lock(string $key): void } - /** - * Writes item into the cache. - * @param string $key - * @param $data - * @param array $dp - */ + /** + * Writes item into the cache. + * @param string $key + * @param $data + * @param array $dp + */ public function write(string $key, $data, array $dp): void { $meta = [ @@ -239,10 +239,10 @@ public function write(string $key, $data, array $dp): void } - /** - * Removes item from the cache. - * @param string $key - */ + /** + * Removes item from the cache. + * @param string $key + */ public function remove(string $key): void { unset($this->locks[$key]); @@ -250,15 +250,15 @@ public function remove(string $key): void } - /** - * Removes items from the cache by conditions & garbage collector. - * @param array $conditions - */ + /** + * Removes items from the cache by conditions & garbage collector. + * @param array $conditions + */ public function clean(array $conditions): void { $all = !empty($conditions[Cache::ALL]); $collector = empty($conditions); - $namespaces = $conditions[Cache::NAMESPACE] ?? false; + $namespaces = $conditions[Cache::NAMESPACE] ?? false; // cleaning using file iterator if ($all || $collector) { @@ -295,20 +295,20 @@ public function clean(array $conditions): void } return; } else if($namespaces) { - if (!is_array($namespaces)) { - $namespaces = [$namespaces]; - } - - foreach ($namespaces as $namespace) { - $dir = $this->dir . "/_$namespace"; - if (is_dir($dir)) { - $items = Nette\Utils\Finder::findFiles('')->from($dir); - foreach ($items as $item) { - $this->delete($item); - } - @rmdir($dir); - } - } + if (!is_array($namespaces)) { + $namespaces = [$namespaces]; + } + + foreach ($namespaces as $namespace) { + $dir = $this->dir . "/_$namespace"; + if (is_dir($dir)) { + $items = Nette\Utils\Finder::findFiles('')->from($dir); + foreach ($items as $item) { + $this->delete($item); + } + @rmdir($dir); + } + } } // cleaning using journal @@ -320,12 +320,12 @@ public function clean(array $conditions): void } - /** - * Reads cache data from disk. - * @param string $file path - * @param int $lock mode - * @return array|null - */ + /** + * Reads cache data from disk. + * @param string $file path + * @param int $lock mode + * @return array|null + */ protected function readMetaAndLock(string $file, int $lock): ?array { $handle = @fopen($file, 'r+b'); // @ - file may not exist @@ -351,11 +351,11 @@ protected function readMetaAndLock(string $file, int $lock): ?array } - /** - * Reads cache data from disk and closes cache file handle. - * @param array $meta - * @return mixed - */ + /** + * Reads cache data from disk and closes cache file handle. + * @param array $meta + * @return mixed + */ protected function readData(array $meta) { $data = stream_get_contents($meta[self::HANDLE]); @@ -370,11 +370,11 @@ protected function readData(array $meta) } - /** - * Returns file name. - * @param string $key - * @return string - */ + /** + * Returns file name. + * @param string $key + * @return string + */ protected function getCacheFile(string $key): string { $file = urlencode($key); @@ -385,11 +385,11 @@ protected function getCacheFile(string $key): string } - /** - * Deletes and closes file. - * @param string $file - * @param resource $handle - */ + /** + * Deletes and closes file. + * @param string $file + * @param resource $handle + */ private static function delete(string $file, $handle = null): void { if (@unlink($file)) { // @ - file may not already exist diff --git a/src/Caching/Storages/SQLiteStorage.php b/src/Caching/Storages/SQLiteStorage.php index d59cfd81..4d6b5f83 100644 --- a/src/Caching/Storages/SQLiteStorage.php +++ b/src/Caching/Storages/SQLiteStorage.php @@ -52,11 +52,11 @@ public function __construct($path) } - /** - * Read from cache. - * @param string $key - * @return mixed - */ + /** + * Read from cache. + * @param string $key + * @return mixed + */ public function read(string $key) { $stmt = $this->pdo->prepare('SELECT data, slide FROM cache WHERE key=? AND (expire IS NULL OR expire >= ?)'); @@ -70,11 +70,11 @@ public function read(string $key) } - /** - * Reads from cache in bulk. - * @param array $keys - * @return array key => value pairs, missing items are omitted - */ + /** + * Reads from cache in bulk. + * @param array $keys + * @return array key => value pairs, missing items are omitted + */ public function bulkRead(array $keys): array { $stmt = $this->pdo->prepare('SELECT key, data, slide FROM cache WHERE key IN (?' . str_repeat(',?', count($keys) - 1) . ') AND (expire IS NULL OR expire >= ?)'); @@ -95,21 +95,21 @@ public function bulkRead(array $keys): array } - /** - * Prevents item reading and writing. Lock is released by write() or remove(). - * @param string $key - */ + /** + * Prevents item reading and writing. Lock is released by write() or remove(). + * @param string $key + */ public function lock(string $key): void { } - /** - * Writes item into the cache. - * @param string $key - * @param $data - * @param array $dependencies - */ + /** + * Writes item into the cache. + * @param string $key + * @param $data + * @param array $dependencies + */ public function write(string $key, $data, array $dependencies): void { $expire = isset($dependencies[Cache::EXPIRATION]) ? $dependencies[Cache::EXPIRATION] + time() : null; @@ -131,10 +131,10 @@ public function write(string $key, $data, array $dependencies): void } - /** - * Removes item from the cache. - * @param string $key - */ + /** + * Removes item from the cache. + * @param string $key + */ public function remove(string $key): void { $this->pdo->prepare('DELETE FROM cache WHERE key=?') @@ -142,10 +142,10 @@ public function remove(string $key): void } - /** - * Removes items from the cache by conditions & garbage collector. - * @param array $conditions - */ + /** + * Removes items from the cache by conditions & garbage collector. + * @param array $conditions + */ public function clean(array $conditions): void { if (!empty($conditions[Cache::ALL])) { @@ -160,17 +160,17 @@ public function clean(array $conditions): void $args = array_merge($args, $tags); } - $this->pdo->prepare($sql)->execute($args); - } elseif (!empty($conditions[Cache::NAMESPACE])) { - if (is_array($conditions[Cache::NAMESPACE])) { - $namespaces = $conditions[Cache::NAMESPACE]; - } else { - $namespaces = [$conditions[Cache::NAMESPACE]]; - } - - foreach ($namespaces as $namespace) { - $this->pdo->prepare("DELETE FROM cache WHERE key LIKE %/_$namespace/%")->execute(); - } - } + $this->pdo->prepare($sql)->execute($args); + } elseif (!empty($conditions[Cache::NAMESPACE])) { + if (is_array($conditions[Cache::NAMESPACE])) { + $namespaces = $conditions[Cache::NAMESPACE]; + } else { + $namespaces = [$conditions[Cache::NAMESPACE]]; + } + + foreach ($namespaces as $namespace) { + $this->pdo->prepare("DELETE FROM cache WHERE key LIKE %/_$namespace/%")->execute(); + } + } } } From 832696ad37aec8bd0dd42dc9f3e04c51d57bddbd Mon Sep 17 00:00:00 2001 From: aiphee Date: Sat, 5 Aug 2017 21:25:17 +0200 Subject: [PATCH 03/11] Added test and removed altered comments --- src/Caching/Cache.php | 25 ++------ src/Caching/Storages/FileStorage.php | 18 +----- src/Caching/Storages/SQLiteStorage.php | 8 --- .../Storages/FileStorage.clean-namespace.phpt | 60 +++++++++++++++++++ 4 files changed, 67 insertions(+), 44 deletions(-) create mode 100644 tests/Storages/FileStorage.clean-namespace.phpt diff --git a/src/Caching/Cache.php b/src/Caching/Cache.php index 3e36a21b..e14366de 100644 --- a/src/Caching/Cache.php +++ b/src/Caching/Cache.php @@ -82,8 +82,7 @@ public function derive(string $namespace) /** * Reads the specified item from the cache or generate it. - * @param $key - * @param callable|null $fallback + * @param mixed * @return mixed */ public function load($key, callable $fallback = null) @@ -100,9 +99,6 @@ public function load($key, callable $fallback = null) /** * Reads multiple items from the cache. - * @param array $keys - * @param callable|null $fallback - * @return array */ public function bulkLoad(array $keys, callable $fallback = null): array { @@ -158,11 +154,10 @@ public function bulkLoad(array $keys, callable $fallback = null): array * - Cache::ITEMS => (array|string) cache items * - Cache::CONSTS => (array|string) cache items * - * @param $key - * @param $data - * @param array|null $dependencies + * @param mixed + * @param mixed * @return mixed value itself - * @throws \Throwable + * @throws Nette\InvalidArgumentException */ public function save($key, $data, array $dependencies = null) { @@ -248,7 +243,6 @@ public function remove($key): void * - Cache::PRIORITY => (int) priority * - Cache::TAGS => (array) tags * - Cache::ALL => true - * @param array|null $conditions */ public function clean(array $conditions = null): void { @@ -279,10 +273,7 @@ public function call($function) /** * Caches results of function/method calls. - * @param $function - * @param array|null $dependencies - * @return \Closure - * @internal param $mixed + * @param mixed */ public function wrap($function, array $dependencies = null): \Closure { @@ -343,9 +334,6 @@ public static function checkCallbacks(array $callbacks): bool /** * Checks CONSTS dependency. - * @param string $const - * @param $value - * @return bool */ private static function checkConst(string $const, $value): bool { @@ -355,9 +343,6 @@ private static function checkConst(string $const, $value): bool /** * Checks FILES dependency. - * @param string $file - * @param int|null $time - * @return bool */ private static function checkFile(string $file, ?int $time): bool { diff --git a/src/Caching/Storages/FileStorage.php b/src/Caching/Storages/FileStorage.php index 9c8ef794..5af3232b 100644 --- a/src/Caching/Storages/FileStorage.php +++ b/src/Caching/Storages/FileStorage.php @@ -81,7 +81,6 @@ public function __construct($dir, IJournal $journal = null) /** * Read from cache. - * @param string $key * @return mixed */ public function read(string $key) @@ -98,8 +97,6 @@ public function read(string $key) /** * Verifies dependencies. - * @param array $meta - * @return bool */ private function verify(array $meta): bool { @@ -138,7 +135,6 @@ private function verify(array $meta): bool /** * Prevents item reading and writing. Lock is released by write() or remove(). - * @param string $key */ public function lock(string $key): void { @@ -156,9 +152,6 @@ public function lock(string $key): void /** * Writes item into the cache. - * @param string $key - * @param $data - * @param array $dp */ public function write(string $key, $data, array $dp): void { @@ -241,7 +234,6 @@ public function write(string $key, $data, array $dp): void /** * Removes item from the cache. - * @param string $key */ public function remove(string $key): void { @@ -252,7 +244,6 @@ public function remove(string $key): void /** * Removes items from the cache by conditions & garbage collector. - * @param array $conditions */ public function clean(array $conditions): void { @@ -322,9 +313,8 @@ public function clean(array $conditions): void /** * Reads cache data from disk. - * @param string $file path - * @param int $lock mode - * @return array|null + * @param string file path + * @param int lock mode */ protected function readMetaAndLock(string $file, int $lock): ?array { @@ -353,7 +343,6 @@ protected function readMetaAndLock(string $file, int $lock): ?array /** * Reads cache data from disk and closes cache file handle. - * @param array $meta * @return mixed */ protected function readData(array $meta) @@ -372,8 +361,6 @@ protected function readData(array $meta) /** * Returns file name. - * @param string $key - * @return string */ protected function getCacheFile(string $key): string { @@ -387,7 +374,6 @@ protected function getCacheFile(string $key): string /** * Deletes and closes file. - * @param string $file * @param resource $handle */ private static function delete(string $file, $handle = null): void diff --git a/src/Caching/Storages/SQLiteStorage.php b/src/Caching/Storages/SQLiteStorage.php index 4d6b5f83..75e8bc09 100644 --- a/src/Caching/Storages/SQLiteStorage.php +++ b/src/Caching/Storages/SQLiteStorage.php @@ -54,7 +54,6 @@ public function __construct($path) /** * Read from cache. - * @param string $key * @return mixed */ public function read(string $key) @@ -72,7 +71,6 @@ public function read(string $key) /** * Reads from cache in bulk. - * @param array $keys * @return array key => value pairs, missing items are omitted */ public function bulkRead(array $keys): array @@ -97,7 +95,6 @@ public function bulkRead(array $keys): array /** * Prevents item reading and writing. Lock is released by write() or remove(). - * @param string $key */ public function lock(string $key): void { @@ -106,9 +103,6 @@ public function lock(string $key): void /** * Writes item into the cache. - * @param string $key - * @param $data - * @param array $dependencies */ public function write(string $key, $data, array $dependencies): void { @@ -133,7 +127,6 @@ public function write(string $key, $data, array $dependencies): void /** * Removes item from the cache. - * @param string $key */ public function remove(string $key): void { @@ -144,7 +137,6 @@ public function remove(string $key): void /** * Removes items from the cache by conditions & garbage collector. - * @param array $conditions */ public function clean(array $conditions): void { diff --git a/tests/Storages/FileStorage.clean-namespace.phpt b/tests/Storages/FileStorage.clean-namespace.phpt new file mode 100644 index 00000000..cce5ff31 --- /dev/null +++ b/tests/Storages/FileStorage.clean-namespace.phpt @@ -0,0 +1,60 @@ +save('test1', 'David'); +$cacheA->save('test2', 'Grudl'); +$cacheB->save('test1', 'divaD'); +$cacheB->save('test2', 'ldurG'); +$cacheC->save('test1', 'Forst'); +$cacheC->save('test2', 'tsroF'); + +Assert::same('David Grudl', implode(' ', [ + $cacheA->load('test1'), + $cacheA->load('test2'), +])); + +Assert::same('divaD ldurG', implode(' ', [ + $cacheB->load('test1'), + $cacheB->load('test2'), +])); + +Assert::same('Forst tsroF', implode(' ', [ + $cacheC->load('test1'), + $cacheC->load('test2'), +])); + + +$storage->clean([Cache::NAMESPACE => 'C']); + + +Assert::same('David Grudl', implode(' ', [ + $cacheA->load('test1'), + $cacheA->load('test2'), +])); + +Assert::same('divaD ldurG', implode(' ', [ + $cacheB->load('test1'), + $cacheB->load('test2'), +])); + + +Assert::null($cacheC->load('test1')); +Assert::null($cacheC->load('test2')); From cb7c1d568bea0895a53e917f50115d2b685a037a Mon Sep 17 00:00:00 2001 From: aiphee Date: Sat, 5 Aug 2017 21:52:44 +0200 Subject: [PATCH 04/11] Repair for type checking --- src/Caching/Storages/FileStorage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Caching/Storages/FileStorage.php b/src/Caching/Storages/FileStorage.php index 5af3232b..f0b8f02e 100644 --- a/src/Caching/Storages/FileStorage.php +++ b/src/Caching/Storages/FileStorage.php @@ -295,7 +295,7 @@ public function clean(array $conditions): void if (is_dir($dir)) { $items = Nette\Utils\Finder::findFiles('')->from($dir); foreach ($items as $item) { - $this->delete($item); + $this->delete((string)$item); } @rmdir($dir); } From 9cca0892a47e47b29ffe59b0a41d480c075a3177 Mon Sep 17 00:00:00 2001 From: aiphee Date: Sat, 5 Aug 2017 22:04:32 +0200 Subject: [PATCH 05/11] code-checker --- src/Caching/Storages/FileStorage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Caching/Storages/FileStorage.php b/src/Caching/Storages/FileStorage.php index f0b8f02e..eb298692 100644 --- a/src/Caching/Storages/FileStorage.php +++ b/src/Caching/Storages/FileStorage.php @@ -285,7 +285,7 @@ public function clean(array $conditions): void $this->journal->clean($conditions); } return; - } else if($namespaces) { + } elseif ($namespaces) { if (!is_array($namespaces)) { $namespaces = [$namespaces]; } @@ -295,7 +295,7 @@ public function clean(array $conditions): void if (is_dir($dir)) { $items = Nette\Utils\Finder::findFiles('')->from($dir); foreach ($items as $item) { - $this->delete((string)$item); + $this->delete((string) $item); } @rmdir($dir); } From d8fecb48defa6da67f8bb151b0d63976e02d41d1 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 9 Aug 2017 17:25:14 +0200 Subject: [PATCH 06/11] coding style --- tests/Bridges.Latte/CacheMacro.createCache.phpt | 6 +++--- tests/Caching/Cache.bulkLoad.phpt | 2 +- tests/Caching/Cache.load.phpt | 4 ++-- tests/Caching/Cache.save.phpt | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/Bridges.Latte/CacheMacro.createCache.phpt b/tests/Bridges.Latte/CacheMacro.createCache.phpt index 263353d0..d2b29f9e 100644 --- a/tests/Bridges.Latte/CacheMacro.createCache.phpt +++ b/tests/Bridges.Latte/CacheMacro.createCache.phpt @@ -17,7 +17,7 @@ require __DIR__ . '/../bootstrap.php'; test(function () { $parents = []; $dp = [Cache::TAGS => ['rum', 'cola']]; - $outputHelper = CacheMacro::createCache(new DevNullStorage(), 'test', $parents); + $outputHelper = CacheMacro::createCache(new DevNullStorage, 'test', $parents); Assert::type(Nette\Caching\OutputHelper::class, $outputHelper); CacheMacro::endCache($parents, $dp); Assert::same($dp + [Cache::EXPIRATION => '+ 7 days'], $outputHelper->dependencies); @@ -29,7 +29,7 @@ test(function () { $dpFallback = function () use ($dp) { return $dp; }; - $outputHelper = CacheMacro::createCache(new DevNullStorage(), 'test', $parents); + $outputHelper = CacheMacro::createCache(new DevNullStorage, 'test', $parents); CacheMacro::endCache($parents, ['dependencies' => $dpFallback]); Assert::same($dp + [Cache::EXPIRATION => '+ 7 days'], $outputHelper->dependencies); }); @@ -43,7 +43,7 @@ test(function () { $dpFallback = function () use ($dp) { return $dp; }; - $outputHelper = CacheMacro::createCache(new DevNullStorage(), 'test', $parents); + $outputHelper = CacheMacro::createCache(new DevNullStorage, 'test', $parents); CacheMacro::endCache($parents, ['dependencies' => $dpFallback]); Assert::same($dp, $outputHelper->dependencies); }); diff --git a/tests/Caching/Cache.bulkLoad.phpt b/tests/Caching/Cache.bulkLoad.phpt index 782edf5e..37b1f69b 100644 --- a/tests/Caching/Cache.bulkLoad.phpt +++ b/tests/Caching/Cache.bulkLoad.phpt @@ -60,7 +60,7 @@ test(function () { test(function () { Assert::exception(function () { - $cache = new Cache(new BulkReadTestStorage()); + $cache = new Cache(new BulkReadTestStorage); $cache->bulkLoad([[1]]); }, Nette\InvalidArgumentException::class, 'Only scalar keys are allowed in bulkLoad()'); }); diff --git a/tests/Caching/Cache.load.phpt b/tests/Caching/Cache.load.phpt index 7caa2a9e..6437f9c4 100644 --- a/tests/Caching/Cache.load.phpt +++ b/tests/Caching/Cache.load.phpt @@ -16,7 +16,7 @@ require __DIR__ . '/Cache.php'; // load twice with fallback -$storage = new TestStorage(); +$storage = new TestStorage; $cache = new Cache($storage, 'ns'); $value = $cache->load('key', function () { @@ -32,7 +32,7 @@ Assert::equal('value', $data['data']); // load twice with closure fallback, pass dependencies $dependencies = [Cache::TAGS => ['tag']]; -$storage = new TestStorage(); +$storage = new TestStorage; $cache = new Cache($storage, 'ns'); $value = $cache->load('key', function (&$deps) use ($dependencies) { diff --git a/tests/Caching/Cache.save.phpt b/tests/Caching/Cache.save.phpt index 6dbcba8b..06683c03 100644 --- a/tests/Caching/Cache.save.phpt +++ b/tests/Caching/Cache.save.phpt @@ -16,7 +16,7 @@ require __DIR__ . '/Cache.php'; // save value with dependencies -$storage = new testStorage(); +$storage = new testStorage; $cache = new Cache($storage, 'ns'); $dependencies = [Cache::TAGS => ['tag']]; @@ -28,7 +28,7 @@ Assert::equal($dependencies, $res['dependencies']); // save callback return value -$storage = new testStorage(); +$storage = new testStorage; $cache = new Cache($storage, 'ns'); $cache->save('key', function () { @@ -41,7 +41,7 @@ Assert::equal([], $res['dependencies']); // save callback return value with dependencies -$storage = new testStorage(); +$storage = new testStorage; $cache = new Cache($storage, 'ns'); $dependencies = [Cache::TAGS => ['tag']]; @@ -55,7 +55,7 @@ Assert::equal($dependencies, $res['dependencies']); // do not save already expired data -$storage = new testStorage(); +$storage = new testStorage; $cache = new Cache($storage, 'ns'); $dependencies = [Cache::EXPIRATION => new DateTime]; From faabb14c83ee1bcf1060c062169c1dcf04190299 Mon Sep 17 00:00:00 2001 From: aiphee Date: Fri, 11 Aug 2017 20:58:15 +0200 Subject: [PATCH 07/11] Repair things from review, add test for cleaning SQLite namespace --- src/Caching/Cache.php | 3 +- src/Caching/Storages/FileStorage.php | 8 +- src/Caching/Storages/SQLiteStorage.php | 13 +- .../Storages/FileStorage.clean-namespace.phpt | 82 ++++++++++--- tests/Storages/SQLiteJournal.phpt | 3 + .../SQLiteStorage.clean-namespace.phpt | 114 ++++++++++++++++++ 6 files changed, 197 insertions(+), 26 deletions(-) create mode 100644 tests/Storages/SQLiteStorage.clean-namespace.phpt diff --git a/src/Caching/Cache.php b/src/Caching/Cache.php index e14366de..cb922258 100644 --- a/src/Caching/Cache.php +++ b/src/Caching/Cache.php @@ -31,10 +31,9 @@ class Cache ITEMS = 'items', CONSTS = 'consts', CALLBACKS = 'callbacks', - NAMESPACE = 'namespace', + NAMESPACES = 'namespaces', ALL = 'all'; - /** @internal */ public const NAMESPACE_SEPARATOR = "\x00"; /** @var IStorage */ diff --git a/src/Caching/Storages/FileStorage.php b/src/Caching/Storages/FileStorage.php index eb298692..07d39388 100644 --- a/src/Caching/Storages/FileStorage.php +++ b/src/Caching/Storages/FileStorage.php @@ -153,7 +153,7 @@ public function lock(string $key): void /** * Writes item into the cache. */ - public function write(string $key, $data, array $dp): void + public function write(string $key, $data, array $dp = []): void { $meta = [ self::META_TIME => microtime(), @@ -291,13 +291,13 @@ public function clean(array $conditions): void } foreach ($namespaces as $namespace) { - $dir = $this->dir . "/_$namespace"; + $dir = $this->dir . '/_' . urlencode($namespace); if (is_dir($dir)) { - $items = Nette\Utils\Finder::findFiles('')->from($dir); + $items = Nette\Utils\Finder::findFiles('*')->from($dir); foreach ($items as $item) { $this->delete((string) $item); } - @rmdir($dir); + @rmdir($dir); // may already contain new files } } } diff --git a/src/Caching/Storages/SQLiteStorage.php b/src/Caching/Storages/SQLiteStorage.php index 75e8bc09..9ff42b68 100644 --- a/src/Caching/Storages/SQLiteStorage.php +++ b/src/Caching/Storages/SQLiteStorage.php @@ -153,15 +153,18 @@ public function clean(array $conditions): void } $this->pdo->prepare($sql)->execute($args); - } elseif (!empty($conditions[Cache::NAMESPACE])) { - if (is_array($conditions[Cache::NAMESPACE])) { - $namespaces = $conditions[Cache::NAMESPACE]; + } elseif (!empty($conditions[Cache::NAMESPACES])) { + if (is_array($conditions[Cache::NAMESPACES])) { + $namespaces = $conditions[Cache::NAMESPACES]; } else { - $namespaces = [$conditions[Cache::NAMESPACE]]; + $namespaces = [$conditions[Cache::NAMESPACES]]; } + foreach ($namespaces as $namespace) { - $this->pdo->prepare("DELETE FROM cache WHERE key LIKE %/_$namespace/%")->execute(); + $this->pdo + ->prepare('DELETE FROM cache WHERE key LIKE ?') + ->execute([$namespace . Cache::NAMESPACE_SEPARATOR]); } } } diff --git a/tests/Storages/FileStorage.clean-namespace.phpt b/tests/Storages/FileStorage.clean-namespace.phpt index cce5ff31..9e469ad9 100644 --- a/tests/Storages/FileStorage.clean-namespace.phpt +++ b/tests/Storages/FileStorage.clean-namespace.phpt @@ -13,48 +13,100 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; - $storage = new FileStorage(TEMP_DIR); + +/* + * Create filestorage cache without namespace and some with namespaces + */ $cacheA = new Cache($storage); $cacheB = new Cache($storage, 'B'); $cacheC = new Cache($storage, 'C'); +$cacheD = new Cache($storage, 'D'); +/* + * Fill with data + */ $cacheA->save('test1', 'David'); $cacheA->save('test2', 'Grudl'); -$cacheB->save('test1', 'divaD'); -$cacheB->save('test2', 'ldurG'); -$cacheC->save('test1', 'Forst'); -$cacheC->save('test2', 'tsroF'); +$cacheB->save('test1', 'Barry'); +$cacheB->save('test2', 'Allen'); + +$cacheC->save('test1', 'Oliver'); +$cacheC->save('test2', 'Queen'); + +$cacheD->save('test1', 'Bruce'); +$cacheD->save('test2', 'Wayne'); + + +/* + * Check if fill wass successfull + */ Assert::same('David Grudl', implode(' ', [ $cacheA->load('test1'), - $cacheA->load('test2'), + $cacheA->load('test2') ])); -Assert::same('divaD ldurG', implode(' ', [ +Assert::same('Barry Allen', implode(' ', [ $cacheB->load('test1'), - $cacheB->load('test2'), + $cacheB->load('test2') ])); -Assert::same('Forst tsroF', implode(' ', [ +Assert::same('Oliver Queen', implode(' ', [ $cacheC->load('test1'), - $cacheC->load('test2'), + $cacheC->load('test2') ])); +Assert::same('Bruce Wayne', implode(' ', [ + $cacheD->load('test1'), + $cacheD->load('test2') +])); -$storage->clean([Cache::NAMESPACE => 'C']); +/* + * Clean one namespace + */ +$storage->clean([Cache::NAMESPACES => 'B']); Assert::same('David Grudl', implode(' ', [ $cacheA->load('test1'), - $cacheA->load('test2'), + $cacheA->load('test2') ])); -Assert::same('divaD ldurG', implode(' ', [ - $cacheB->load('test1'), - $cacheB->load('test2'), +// Only these should be null now +Assert::null($cacheB->load('test1')); +Assert::null($cacheB->load('test2')); + +Assert::same('Oliver Queen', implode(' ', [ + $cacheC->load('test1'), + $cacheC->load('test2') ])); +Assert::same('Bruce Wayne', implode(' ', [ + $cacheD->load('test1'), + $cacheD->load('test2') +])); + + +/* + * Test cleaning multiple namespaces + */ +$storage->clean([Cache::NAMESPACES => ['C', 'D']]); + +Assert::same('David Grudl', implode(' ', [ + $cacheA->load('test1'), + $cacheA->load('test2') +])); + +// All other should be null +Assert::null($cacheB->load('test1')); +Assert::null($cacheB->load('test2')); Assert::null($cacheC->load('test1')); Assert::null($cacheC->load('test2')); + +Assert::null($cacheD->load('test1')); +Assert::null($cacheD->load('test2')); + + + diff --git a/tests/Storages/SQLiteJournal.phpt b/tests/Storages/SQLiteJournal.phpt index a23d3fba..48aee12e 100644 --- a/tests/Storages/SQLiteJournal.phpt +++ b/tests/Storages/SQLiteJournal.phpt @@ -14,6 +14,9 @@ require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/IJournalTestCase.php'; +/** + * @testCase + */ class SQLiteJournalTest extends IJournalTestCase { public function createJournal() diff --git a/tests/Storages/SQLiteStorage.clean-namespace.phpt b/tests/Storages/SQLiteStorage.clean-namespace.phpt new file mode 100644 index 00000000..d5fda68c --- /dev/null +++ b/tests/Storages/SQLiteStorage.clean-namespace.phpt @@ -0,0 +1,114 @@ +save('test1', 'David'); +$cacheA->save('test2', 'Grudl'); + +$cacheB->save('test1', 'Barry'); +$cacheB->save('test2', 'Allen'); + +$cacheC->save('test1', 'Oliver'); +$cacheC->save('test2', 'Queen'); + +$cacheD->save('test1', 'Bruce'); +$cacheD->save('test2', 'Wayne'); + + +/* + * Check if fill wass successfull + */ +Assert::same('David Grudl', implode(' ', [ + $cacheA->load('test1'), + $cacheA->load('test2') +])); + +Assert::same('Barry Allen', implode(' ', [ + $cacheB->load('test1'), + $cacheB->load('test2') +])); + +Assert::same('Oliver Queen', implode(' ', [ + $cacheC->load('test1'), + $cacheC->load('test2') +])); + +Assert::same('Bruce Wayne', implode(' ', [ + $cacheD->load('test1'), + $cacheD->load('test2') +])); + + +/* + * Clean one namespace + */ +$storage->clean([Cache::NAMESPACES => 'B']); + +Assert::same('David Grudl', implode(' ', [ + $cacheA->load('test1'), + $cacheA->load('test2') +])); + +// Only these should be null now +Assert::null($cacheB->load('test1')); +Assert::null($cacheB->load('test2')); + +Assert::same('Oliver Queen', implode(' ', [ + $cacheC->load('test1'), + $cacheC->load('test2') +])); + +Assert::same('Bruce Wayne', implode(' ', [ + $cacheD->load('test1'), + $cacheD->load('test2') +])); + + +/* + * Test cleaning multiple namespaces + */ +$storage->clean([Cache::NAMESPACES => ['C', 'D']]); + +Assert::same('David Grudl', implode(' ', [ + $cacheA->load('test1'), + $cacheA->load('test2') +])); + +// All other should be null +Assert::null($cacheB->load('test1')); +Assert::null($cacheB->load('test2')); + +Assert::null($cacheC->load('test1')); +Assert::null($cacheC->load('test2')); + +Assert::null($cacheD->load('test1')); +Assert::null($cacheD->load('test2')); + + + From 7af25bb7e2bbaad3eaccc20ec0dc8f2269610b24 Mon Sep 17 00:00:00 2001 From: aiphee Date: Fri, 11 Aug 2017 21:40:40 +0200 Subject: [PATCH 08/11] Repair constant --- src/Caching/Storages/FileStorage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Caching/Storages/FileStorage.php b/src/Caching/Storages/FileStorage.php index 07d39388..b800fd8c 100644 --- a/src/Caching/Storages/FileStorage.php +++ b/src/Caching/Storages/FileStorage.php @@ -249,7 +249,7 @@ public function clean(array $conditions): void { $all = !empty($conditions[Cache::ALL]); $collector = empty($conditions); - $namespaces = $conditions[Cache::NAMESPACE] ?? false; + $namespaces = $conditions[Cache::NAMESPACES] ?? false; // cleaning using file iterator if ($all || $collector) { From 5229c3cc7dfe7940e02a57c465e0613191553e00 Mon Sep 17 00:00:00 2001 From: aiphee Date: Fri, 11 Aug 2017 22:05:16 +0200 Subject: [PATCH 09/11] Group use declaration is disallowed --- tests/Storages/SQLiteStorage.clean-namespace.phpt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/Storages/SQLiteStorage.clean-namespace.phpt b/tests/Storages/SQLiteStorage.clean-namespace.phpt index d5fda68c..9c1f8b84 100644 --- a/tests/Storages/SQLiteStorage.clean-namespace.phpt +++ b/tests/Storages/SQLiteStorage.clean-namespace.phpt @@ -7,9 +7,8 @@ declare(strict_types=1); -use Nette\Caching\{ - Cache, Storages\SQLiteStorage -}; +use Nette\Caching\Cache; +use Nette\Caching\Storages\SQLiteStorage; use Tester\Assert; From 0b2ed5284ea29836c4184ee535a31f6ebf6615e5 Mon Sep 17 00:00:00 2001 From: aiphee Date: Fri, 11 Aug 2017 22:16:12 +0200 Subject: [PATCH 10/11] cs --- .../Storages/FileStorage.clean-namespace.phpt | 19 ++++++------- .../SQLiteStorage.clean-namespace.phpt | 19 ++++++------- tests/php-unix.ini | 27 +++++++++++++++++-- 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/tests/Storages/FileStorage.clean-namespace.phpt b/tests/Storages/FileStorage.clean-namespace.phpt index 9e469ad9..0ff64e9e 100644 --- a/tests/Storages/FileStorage.clean-namespace.phpt +++ b/tests/Storages/FileStorage.clean-namespace.phpt @@ -44,22 +44,22 @@ $cacheD->save('test2', 'Wayne'); */ Assert::same('David Grudl', implode(' ', [ $cacheA->load('test1'), - $cacheA->load('test2') + $cacheA->load('test2'), ])); Assert::same('Barry Allen', implode(' ', [ $cacheB->load('test1'), - $cacheB->load('test2') + $cacheB->load('test2'), ])); Assert::same('Oliver Queen', implode(' ', [ $cacheC->load('test1'), - $cacheC->load('test2') + $cacheC->load('test2'), ])); Assert::same('Bruce Wayne', implode(' ', [ $cacheD->load('test1'), - $cacheD->load('test2') + $cacheD->load('test2'), ])); @@ -70,7 +70,7 @@ $storage->clean([Cache::NAMESPACES => 'B']); Assert::same('David Grudl', implode(' ', [ $cacheA->load('test1'), - $cacheA->load('test2') + $cacheA->load('test2'), ])); // Only these should be null now @@ -79,12 +79,12 @@ Assert::null($cacheB->load('test2')); Assert::same('Oliver Queen', implode(' ', [ $cacheC->load('test1'), - $cacheC->load('test2') + $cacheC->load('test2'), ])); Assert::same('Bruce Wayne', implode(' ', [ $cacheD->load('test1'), - $cacheD->load('test2') + $cacheD->load('test2'), ])); @@ -95,7 +95,7 @@ $storage->clean([Cache::NAMESPACES => ['C', 'D']]); Assert::same('David Grudl', implode(' ', [ $cacheA->load('test1'), - $cacheA->load('test2') + $cacheA->load('test2'), ])); // All other should be null @@ -107,6 +107,3 @@ Assert::null($cacheC->load('test2')); Assert::null($cacheD->load('test1')); Assert::null($cacheD->load('test2')); - - - diff --git a/tests/Storages/SQLiteStorage.clean-namespace.phpt b/tests/Storages/SQLiteStorage.clean-namespace.phpt index 9c1f8b84..be2f77a5 100644 --- a/tests/Storages/SQLiteStorage.clean-namespace.phpt +++ b/tests/Storages/SQLiteStorage.clean-namespace.phpt @@ -45,22 +45,22 @@ $cacheD->save('test2', 'Wayne'); */ Assert::same('David Grudl', implode(' ', [ $cacheA->load('test1'), - $cacheA->load('test2') + $cacheA->load('test2'), ])); Assert::same('Barry Allen', implode(' ', [ $cacheB->load('test1'), - $cacheB->load('test2') + $cacheB->load('test2'), ])); Assert::same('Oliver Queen', implode(' ', [ $cacheC->load('test1'), - $cacheC->load('test2') + $cacheC->load('test2'), ])); Assert::same('Bruce Wayne', implode(' ', [ $cacheD->load('test1'), - $cacheD->load('test2') + $cacheD->load('test2'), ])); @@ -71,7 +71,7 @@ $storage->clean([Cache::NAMESPACES => 'B']); Assert::same('David Grudl', implode(' ', [ $cacheA->load('test1'), - $cacheA->load('test2') + $cacheA->load('test2'), ])); // Only these should be null now @@ -80,12 +80,12 @@ Assert::null($cacheB->load('test2')); Assert::same('Oliver Queen', implode(' ', [ $cacheC->load('test1'), - $cacheC->load('test2') + $cacheC->load('test2'), ])); Assert::same('Bruce Wayne', implode(' ', [ $cacheD->load('test1'), - $cacheD->load('test2') + $cacheD->load('test2'), ])); @@ -96,7 +96,7 @@ $storage->clean([Cache::NAMESPACES => ['C', 'D']]); Assert::same('David Grudl', implode(' ', [ $cacheA->load('test1'), - $cacheA->load('test2') + $cacheA->load('test2'), ])); // All other should be null @@ -108,6 +108,3 @@ Assert::null($cacheC->load('test2')); Assert::null($cacheD->load('test1')); Assert::null($cacheD->load('test2')); - - - diff --git a/tests/php-unix.ini b/tests/php-unix.ini index 21af7c42..cab1f444 100644 --- a/tests/php-unix.ini +++ b/tests/php-unix.ini @@ -1,7 +1,30 @@ [PHP] ;extension_dir = "./ext" -extension=memcache.so -extension=memcached.so +extension=bz2.so +extension=ctype.so +extension=curl.so +extension=dom.so +extension=gd.so +extension=gettext.so +extension=iconv.so +extension=intl.so +extension=json.so +extension=mbstring.so +extension=mcrypt.so +extension=mysqli.so +extension=openssl.so +extension=pdo.so +extension=pdo_mysql.so +extension=pdo_sqlite.so +extension=phar.so +extension=soap.so +extension=sockets.so +extension=sqlite3.so +extension=tokenizer.so +extension=xmlreader.so +extension=xmlwriter.so +extension=zip.so +extension=zlib.so [Zend] ;zend_extension="./ext/zend_extension" From 9fd0e39bcc6cc85d2b281e5d6981dd00b961f545 Mon Sep 17 00:00:00 2001 From: aiphee Date: Sat, 12 Aug 2017 13:41:42 +0200 Subject: [PATCH 11/11] cs --- tests/Storages/FileStorage.clean-all.phpt | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Storages/FileStorage.clean-all.phpt b/tests/Storages/FileStorage.clean-all.phpt index 8ba8d296..99b3cb5c 100644 --- a/tests/Storages/FileStorage.clean-all.phpt +++ b/tests/Storages/FileStorage.clean-all.phpt @@ -10,7 +10,6 @@ use Nette\Caching\Cache; use Nette\Caching\Storages\FileStorage; use Tester\Assert; - require __DIR__ . '/../bootstrap.php';