From ab9c89d703f758b1d466dedef4e2bcfcc282a01e Mon Sep 17 00:00:00 2001 From: bnomei Date: Sat, 10 Aug 2024 11:28:41 +0200 Subject: [PATCH] :sparkles: global & atomic --- README.md | 17 ++ classes/Nitro.php | 5 +- classes/Nitro/DirInventory.php | 14 +- classes/Nitro/SingleFileCache.php | 91 ++++++- classes/NitroCache.php | 14 ++ composer.json | 2 +- composer.lock | 334 +++++++++++++------------- index.php | 60 +++-- tests/NitroTest.php | 28 ++- vendor/composer/autoload_classmap.php | 1 + vendor/composer/autoload_static.php | 1 + vendor/composer/installed.php | 8 +- 12 files changed, 363 insertions(+), 212 deletions(-) create mode 100644 classes/NitroCache.php diff --git a/README.md b/README.md index 719cb88..3166149 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,20 @@ Nitro speeds up the loading of content in your Kirby project. a [key-value caching helper](https://github.com/bnomei/kirby3-lapse). - If you load more, you should consider [Boost](https://github.com/bnomei/kirby3-boost) or [Khulan](https://github.com/bnomei/kirby-mongodb) instead. +- If you need to process multiple requests fully concurrently you should not use this plugin. But from my experience + most Kirby projects do not need that. + +## Global & Atomic Cache + +The Nitro cache is a global cache. This means that the cache is shared between all HTTP_HOST environments. This will +make it behave like a single database connection. + +The Nitro cache is by default an atomic cache. This means that the cache will block the cache file for the full duration +of your request to maintain data consistency. This will make it behave like a database with locks. + +> [!WARNING] +> No matter how many php-fpm workers you have, only one will be running at a time when Nitro is in atomic mode! You have +> been warned! But this is the only way to guarantee data consistency, and it will still be wicked fast. ## Setup @@ -129,6 +143,9 @@ return [ | bnomei.nitro. | Default | Description | |-------------------|-----------------------|------------------------------------------------------------------------------| +| global | `true` | all HTTP_HOSTs will share the same cache | +| atomic | `true` | will lock the cache while a request is processed to achieve data consistency | +| sleep | `1000` | duration in MICRO seconds before checking the lock again | | auto-clean-cache | `true` | will clean the cache once before the first get() | | patch-dir-class | always on | monkey-patch the \Kirby\Filesystem\Dir class to use Nitro for caching | | patch-files-class | `true` | monkey-patch the \Kirby\CMS\Files class to use Nitro for caching its content | diff --git a/classes/Nitro.php b/classes/Nitro.php index c57ec79..05fdc8d 100644 --- a/classes/Nitro.php +++ b/classes/Nitro.php @@ -167,7 +167,8 @@ public function flush(): void { // reset in memory cache as it will be written on destruct // and thus would survive the flushing of the directories - $this->cache()->flush(); + $this->cache()->flush(write: false); + $this->dir()->flush(write: false); $internalDir = $this->options['cacheDir']; if (Dir::exists($internalDir)) { @@ -179,8 +180,6 @@ public function flush(): void Dir::remove($dir); } } - - $this->dir()->flush(); } public static ?self $singleton = null; diff --git a/classes/Nitro/DirInventory.php b/classes/Nitro/DirInventory.php index 971dead..46ac16f 100644 --- a/classes/Nitro/DirInventory.php +++ b/classes/Nitro/DirInventory.php @@ -63,15 +63,17 @@ public function set(string|array $key, ?array $input = null): void $this->data[$key] = $input; } - public function flush(): void + public function flush(bool $write = true): void { - $file = $this->file(); - if (file_exists($file)) { - unlink($file); - } - $this->data = []; $this->isDirty = true; + + if ($write) { + $file = $this->file(); + if (file_exists($file)) { + unlink($file); + } + } } private function key(string|array $key): string diff --git a/classes/Nitro/SingleFileCache.php b/classes/Nitro/SingleFileCache.php index 882e3d4..a12f417 100644 --- a/classes/Nitro/SingleFileCache.php +++ b/classes/Nitro/SingleFileCache.php @@ -21,8 +21,12 @@ public function __construct(array $options = []) parent::__construct($options); $this->options = array_merge([ + 'global' => option('bnomei.nitro.global'), + 'atomic' => option('bnomei.nitro.atomic'), + 'sleep' => option('bnomei.nitro.sleep'), 'auto-clean-cache' => option('bnomei.nitro.auto-clean-cache'), 'json-encode-flags' => option('bnomei.nitro.json-encode-flags'), + 'cacheDir' => realpath(__DIR__.'/../').'/cache', // must be here as well for when used without nitro like as uuid cache 'max-dirty-cache' => intval(option('bnomei.nitro.max-dirty-cache')), // @phpstan-ignore-line 'debug' => option('debug'), ], $options); @@ -36,11 +40,13 @@ public function __construct(array $options = []) if ($this->options['auto-clean-cache']) { $this->clean(); } + + $this->atomic(); } public function __destruct() { - $this->write(); + $this->write(lock: false); } public function key(string|array $key): string @@ -134,13 +140,15 @@ public function remove(string|array $key): bool /** * {@inheritDoc} */ - public function flush(): bool + public function flush(bool $write = true): bool { if (count($this->data) === 0) { $this->isDirty++; } $this->data = []; - $this->write(); + if ($write) { + $this->write(); + } return true; } @@ -155,19 +163,34 @@ private function clean(): void protected function file(?string $key = null): string { /** @var FileCache $cache */ - $cache = kirby()->cache('bnomei.nitro.sfc'); + if ($this->options['global']) { + $cache = $this->options['cacheDir']; + } else { + $cache = kirby()->cache('bnomei.nitro.sfc')->root(); + } - return $cache->root().'/single-file-cache.json'; + return $cache.'/single-file-cache.json'; } - public function write(): bool + public function write(bool $lock = true): bool { + $this->unlock(); + if ($this->isDirty === 0) { + if ($lock) { + $this->unlock(); + } + return false; } $this->isDirty = 0; - return F::write($this->file(), json_encode($this->data, $this->options['json-encode-flags'])); + $success = F::write($this->file(), json_encode($this->data, $this->options['json-encode-flags'])); + if ($lock) { + $this->lock(); + } + + return $success; } private static function isCallable(mixed $value): bool @@ -203,4 +226,58 @@ public function count(): int { return count($this->data); } + + private function isLocked() + { + if (! $this->options['atomic']) { + return false; + } + + return F::exists($this->file().'.lock'); + } + + public function lock(): bool + { + if (! $this->options['atomic']) { + return false; + } + + return F::write($this->file().'.lock', date('c')); + } + + public function unlock(): bool + { + if (! $this->options['atomic']) { + return false; + } + + return F::remove($this->file().'.lock'); + } + + private function atomic(): bool + { + if (! $this->options['atomic']) { + return false; + } + + // this is what makes it atomic + // get php max execution time + $maxExecutionTime = (int) ini_get('max_execution_time'); + if ($maxExecutionTime === 0) { + $maxExecutionTime = 30; // default, might happen in xdebug mode + } + $maxCycles = $maxExecutionTime * 1000 * 1000; // seconds to microseconds + $sleep = $this->options['sleep']; + + while ($this->isLocked()) { + $maxCycles -= $sleep; + if ($maxCycles <= 0) { + throw new \Exception('Something is very wrong. SingleFileCache could not get lock within '.$maxExecutionTime.' seconds! Are using xdebug breakpoints or maybe you need to forcibly `kirby nitro:unlock`?'); + } + + usleep($sleep); + } + + return $this->lock(); + } } diff --git a/classes/NitroCache.php b/classes/NitroCache.php new file mode 100644 index 0000000..33828cf --- /dev/null +++ b/classes/NitroCache.php @@ -0,0 +1,14 @@ +cache(), $method], $args); + } +} diff --git a/composer.json b/composer.json index a2b7de6..760aa26 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "bnomei/kirby-nitro", "type": "kirby-plugin", - "version": "1.1.3", + "version": "2.0.0", "description": "Nitro speeds up the loading of content in your Kirby project.", "license": "MIT", "authors": [ diff --git a/composer.lock b/composer.lock index 3e5fddb..4d3f3fe 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "94a9380e2ed0b6def1a5bf7f45406050", + "content-hash": "ad5f22f88551a76ab8d53f045f043b7a", "packages": [ { "name": "getkirby/composer-installer", @@ -917,16 +917,16 @@ }, { "name": "guzzlehttp/guzzle", - "version": "7.9.1", + "version": "7.9.2", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "a629e5b69db96eb4939c1b34114130077dd4c6fc" + "reference": "d281ed313b989f213357e3be1a179f02196ac99b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/a629e5b69db96eb4939c1b34114130077dd4c6fc", - "reference": "a629e5b69db96eb4939c1b34114130077dd4c6fc", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/d281ed313b989f213357e3be1a179f02196ac99b", + "reference": "d281ed313b989f213357e3be1a179f02196ac99b", "shasum": "" }, "require": { @@ -1023,7 +1023,7 @@ ], "support": { "issues": "https://github.com/guzzle/guzzle/issues", - "source": "https://github.com/guzzle/guzzle/tree/7.9.1" + "source": "https://github.com/guzzle/guzzle/tree/7.9.2" }, "funding": [ { @@ -1039,7 +1039,7 @@ "type": "tidelift" } ], - "time": "2024-07-19T16:19:57+00:00" + "time": "2024-07-24T11:22:20+00:00" }, { "name": "guzzlehttp/promises", @@ -1328,16 +1328,16 @@ }, { "name": "illuminate/bus", - "version": "v11.16.0", + "version": "v11.20.0", "source": { "type": "git", "url": "https://github.com/illuminate/bus.git", - "reference": "9a8649eb57a6621eed87ecc18af7eb84aa180992" + "reference": "eb5952412b1401530819bda5b42b09e873ba5fe0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/bus/zipball/9a8649eb57a6621eed87ecc18af7eb84aa180992", - "reference": "9a8649eb57a6621eed87ecc18af7eb84aa180992", + "url": "https://api.github.com/repos/illuminate/bus/zipball/eb5952412b1401530819bda5b42b09e873ba5fe0", + "reference": "eb5952412b1401530819bda5b42b09e873ba5fe0", "shasum": "" }, "require": { @@ -1377,20 +1377,20 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-06-28T20:10:30+00:00" + "time": "2024-08-01T18:54:27+00:00" }, { "name": "illuminate/collections", - "version": "v11.16.0", + "version": "v11.20.0", "source": { "type": "git", "url": "https://github.com/illuminate/collections.git", - "reference": "ba2cf689f7d75315f483334b4efc8c6af1d5159c" + "reference": "dc68a7ccad93f3c2baa0bc8f559431c06391aa75" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/collections/zipball/ba2cf689f7d75315f483334b4efc8c6af1d5159c", - "reference": "ba2cf689f7d75315f483334b4efc8c6af1d5159c", + "url": "https://api.github.com/repos/illuminate/collections/zipball/dc68a7ccad93f3c2baa0bc8f559431c06391aa75", + "reference": "dc68a7ccad93f3c2baa0bc8f559431c06391aa75", "shasum": "" }, "require": { @@ -1432,11 +1432,11 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-07-15T21:44:45+00:00" + "time": "2024-08-01T18:54:27+00:00" }, { "name": "illuminate/conditionable", - "version": "v11.16.0", + "version": "v11.20.0", "source": { "type": "git", "url": "https://github.com/illuminate/conditionable.git", @@ -1482,16 +1482,16 @@ }, { "name": "illuminate/console", - "version": "v11.16.0", + "version": "v11.20.0", "source": { "type": "git", "url": "https://github.com/illuminate/console.git", - "reference": "896cc74364c8bc8ecd8adba98278a482c9626b73" + "reference": "5e62f816d1b361e8b7d7649b246b29a66669c462" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/console/zipball/896cc74364c8bc8ecd8adba98278a482c9626b73", - "reference": "896cc74364c8bc8ecd8adba98278a482c9626b73", + "url": "https://api.github.com/repos/illuminate/console/zipball/5e62f816d1b361e8b7d7649b246b29a66669c462", + "reference": "5e62f816d1b361e8b7d7649b246b29a66669c462", "shasum": "" }, "require": { @@ -1544,20 +1544,20 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-07-15T21:52:09+00:00" + "time": "2024-07-30T07:04:41+00:00" }, { "name": "illuminate/container", - "version": "v11.16.0", + "version": "v11.20.0", "source": { "type": "git", "url": "https://github.com/illuminate/container.git", - "reference": "49183db6643a7efbe9902ca379b8f8a55c802f88" + "reference": "f47be671981a4438257c4fbfc3ad257f4e3e929a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/container/zipball/49183db6643a7efbe9902ca379b8f8a55c802f88", - "reference": "49183db6643a7efbe9902ca379b8f8a55c802f88", + "url": "https://api.github.com/repos/illuminate/container/zipball/f47be671981a4438257c4fbfc3ad257f4e3e929a", + "reference": "f47be671981a4438257c4fbfc3ad257f4e3e929a", "shasum": "" }, "require": { @@ -1595,20 +1595,20 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-07-03T21:04:00+00:00" + "time": "2024-08-05T15:04:01+00:00" }, { "name": "illuminate/contracts", - "version": "v11.16.0", + "version": "v11.20.0", "source": { "type": "git", "url": "https://github.com/illuminate/contracts.git", - "reference": "be935e9d9115a57be74d20176f43fa8a207029f3" + "reference": "34ead9385e0eab7e947807d77da66faf9bdf95ff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/contracts/zipball/be935e9d9115a57be74d20176f43fa8a207029f3", - "reference": "be935e9d9115a57be74d20176f43fa8a207029f3", + "url": "https://api.github.com/repos/illuminate/contracts/zipball/34ead9385e0eab7e947807d77da66faf9bdf95ff", + "reference": "34ead9385e0eab7e947807d77da66faf9bdf95ff", "shasum": "" }, "require": { @@ -1643,20 +1643,20 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-07-09T13:57:38+00:00" + "time": "2024-08-01T19:08:33+00:00" }, { "name": "illuminate/database", - "version": "v11.16.0", + "version": "v11.20.0", "source": { "type": "git", "url": "https://github.com/illuminate/database.git", - "reference": "cf816e7e0d08e2a75b233ad061eed85dd8b6b37f" + "reference": "dae4ab28c830a906a410a168d8ece8fb4ab7b2be" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/database/zipball/cf816e7e0d08e2a75b233ad061eed85dd8b6b37f", - "reference": "cf816e7e0d08e2a75b233ad061eed85dd8b6b37f", + "url": "https://api.github.com/repos/illuminate/database/zipball/dae4ab28c830a906a410a168d8ece8fb4ab7b2be", + "reference": "dae4ab28c830a906a410a168d8ece8fb4ab7b2be", "shasum": "" }, "require": { @@ -1711,11 +1711,11 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-07-15T22:28:28+00:00" + "time": "2024-08-06T14:16:43+00:00" }, { "name": "illuminate/events", - "version": "v11.16.0", + "version": "v11.20.0", "source": { "type": "git", "url": "https://github.com/illuminate/events.git", @@ -1770,7 +1770,7 @@ }, { "name": "illuminate/filesystem", - "version": "v11.16.0", + "version": "v11.20.0", "source": { "type": "git", "url": "https://github.com/illuminate/filesystem.git", @@ -1837,16 +1837,16 @@ }, { "name": "illuminate/http", - "version": "v11.16.0", + "version": "v11.20.0", "source": { "type": "git", "url": "https://github.com/illuminate/http.git", - "reference": "63072ea6bcbd75b75655e0bb2854150a0ed886d3" + "reference": "36ab177d468692fe95acc590b33130e465c2477b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/http/zipball/63072ea6bcbd75b75655e0bb2854150a0ed886d3", - "reference": "63072ea6bcbd75b75655e0bb2854150a0ed886d3", + "url": "https://api.github.com/repos/illuminate/http/zipball/36ab177d468692fe95acc590b33130e465c2477b", + "reference": "36ab177d468692fe95acc590b33130e465c2477b", "shasum": "" }, "require": { @@ -1894,11 +1894,11 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-07-10T19:27:29+00:00" + "time": "2024-08-06T14:16:43+00:00" }, { "name": "illuminate/macroable", - "version": "v11.16.0", + "version": "v11.20.0", "source": { "type": "git", "url": "https://github.com/illuminate/macroable.git", @@ -1944,7 +1944,7 @@ }, { "name": "illuminate/pipeline", - "version": "v11.16.0", + "version": "v11.20.0", "source": { "type": "git", "url": "https://github.com/illuminate/pipeline.git", @@ -1992,7 +1992,7 @@ }, { "name": "illuminate/session", - "version": "v11.16.0", + "version": "v11.20.0", "source": { "type": "git", "url": "https://github.com/illuminate/session.git", @@ -2049,16 +2049,16 @@ }, { "name": "illuminate/support", - "version": "v11.16.0", + "version": "v11.20.0", "source": { "type": "git", "url": "https://github.com/illuminate/support.git", - "reference": "4fd85fffd9a4812386b6e10b2a18272ff9040dbe" + "reference": "40457b4694486e506bad1b5be6de8dc86afce46f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/support/zipball/4fd85fffd9a4812386b6e10b2a18272ff9040dbe", - "reference": "4fd85fffd9a4812386b6e10b2a18272ff9040dbe", + "url": "https://api.github.com/repos/illuminate/support/zipball/40457b4694486e506bad1b5be6de8dc86afce46f", + "reference": "40457b4694486e506bad1b5be6de8dc86afce46f", "shasum": "" }, "require": { @@ -2119,20 +2119,20 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-07-16T13:48:58+00:00" + "time": "2024-08-06T14:20:50+00:00" }, { "name": "illuminate/view", - "version": "v11.16.0", + "version": "v11.20.0", "source": { "type": "git", "url": "https://github.com/illuminate/view.git", - "reference": "daca4922fdb590144657171a06be7babcc0c910e" + "reference": "1a4d9192a35e5fb6e99de53b8214c7ddc46a1201" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/view/zipball/daca4922fdb590144657171a06be7babcc0c910e", - "reference": "daca4922fdb590144657171a06be7babcc0c910e", + "url": "https://api.github.com/repos/illuminate/view/zipball/1a4d9192a35e5fb6e99de53b8214c7ddc46a1201", + "reference": "1a4d9192a35e5fb6e99de53b8214c7ddc46a1201", "shasum": "" }, "require": { @@ -2173,7 +2173,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-06-28T20:10:30+00:00" + "time": "2024-08-01T18:54:27+00:00" }, { "name": "jean85/pretty-package-versions", @@ -2400,16 +2400,16 @@ }, { "name": "laravel/pint", - "version": "v1.16.2", + "version": "v1.17.2", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "51f1ba679a6afe0315621ad143d788bd7ded0eca" + "reference": "e8a88130a25e3f9d4d5785e6a1afca98268ab110" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/51f1ba679a6afe0315621ad143d788bd7ded0eca", - "reference": "51f1ba679a6afe0315621ad143d788bd7ded0eca", + "url": "https://api.github.com/repos/laravel/pint/zipball/e8a88130a25e3f9d4d5785e6a1afca98268ab110", + "reference": "e8a88130a25e3f9d4d5785e6a1afca98268ab110", "shasum": "" }, "require": { @@ -2420,13 +2420,13 @@ "php": "^8.1.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.59.3", - "illuminate/view": "^10.48.12", - "larastan/larastan": "^2.9.7", + "friendsofphp/php-cs-fixer": "^3.61.1", + "illuminate/view": "^10.48.18", + "larastan/larastan": "^2.9.8", "laravel-zero/framework": "^10.4.0", "mockery/mockery": "^1.6.12", "nunomaduro/termwind": "^1.15.1", - "pestphp/pest": "^2.34.8" + "pestphp/pest": "^2.35.0" }, "bin": [ "builds/pint" @@ -2462,7 +2462,7 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2024-07-09T15:58:08+00:00" + "time": "2024-08-06T15:11:54+00:00" }, { "name": "laravel/prompts", @@ -2805,20 +2805,20 @@ }, { "name": "nette/utils", - "version": "v4.0.4", + "version": "v4.0.5", "source": { "type": "git", "url": "https://github.com/nette/utils.git", - "reference": "d3ad0aa3b9f934602cb3e3902ebccf10be34d218" + "reference": "736c567e257dbe0fcf6ce81b4d6dbe05c6899f96" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/utils/zipball/d3ad0aa3b9f934602cb3e3902ebccf10be34d218", - "reference": "d3ad0aa3b9f934602cb3e3902ebccf10be34d218", + "url": "https://api.github.com/repos/nette/utils/zipball/736c567e257dbe0fcf6ce81b4d6dbe05c6899f96", + "reference": "736c567e257dbe0fcf6ce81b4d6dbe05c6899f96", "shasum": "" }, "require": { - "php": ">=8.0 <8.4" + "php": "8.0 - 8.4" }, "conflict": { "nette/finder": "<3", @@ -2885,9 +2885,9 @@ ], "support": { "issues": "https://github.com/nette/utils/issues", - "source": "https://github.com/nette/utils/tree/v4.0.4" + "source": "https://github.com/nette/utils/tree/v4.0.5" }, - "time": "2024-01-17T16:50:36+00:00" + "time": "2024-08-07T15:39:19+00:00" }, { "name": "nikic/php-parser", @@ -2949,23 +2949,23 @@ }, { "name": "nunomaduro/collision", - "version": "v8.3.0", + "version": "v8.4.0", "source": { "type": "git", "url": "https://github.com/nunomaduro/collision.git", - "reference": "b49f5b2891ce52726adfd162841c69d4e4c84229" + "reference": "e7d1aa8ed753f63fa816932bbc89678238843b4a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nunomaduro/collision/zipball/b49f5b2891ce52726adfd162841c69d4e4c84229", - "reference": "b49f5b2891ce52726adfd162841c69d4e4c84229", + "url": "https://api.github.com/repos/nunomaduro/collision/zipball/e7d1aa8ed753f63fa816932bbc89678238843b4a", + "reference": "e7d1aa8ed753f63fa816932bbc89678238843b4a", "shasum": "" }, "require": { "filp/whoops": "^2.15.4", "nunomaduro/termwind": "^2.0.1", "php": "^8.2.0", - "symfony/console": "^7.1.2" + "symfony/console": "^7.1.3" }, "conflict": { "laravel/framework": "<11.0.0 || >=12.0.0", @@ -2973,13 +2973,13 @@ }, "require-dev": { "larastan/larastan": "^2.9.8", - "laravel/framework": "^11.16.0", - "laravel/pint": "^1.16.2", - "laravel/sail": "^1.30.2", + "laravel/framework": "^11.19.0", + "laravel/pint": "^1.17.1", + "laravel/sail": "^1.31.0", "laravel/sanctum": "^4.0.2", "laravel/tinker": "^2.9.0", - "orchestra/testbench-core": "^9.2.1", - "pestphp/pest": "^2.34.9 || ^3.0.0", + "orchestra/testbench-core": "^9.2.3", + "pestphp/pest": "^2.35.0 || ^3.0.0", "sebastian/environment": "^6.1.0 || ^7.0.0" }, "type": "library", @@ -3042,7 +3042,7 @@ "type": "patreon" } ], - "time": "2024-07-16T22:41:01+00:00" + "time": "2024-08-03T15:32:23+00:00" }, { "name": "nunomaduro/termwind", @@ -3134,21 +3134,21 @@ }, { "name": "pestphp/pest", - "version": "v2.34.9", + "version": "v2.35.0", "source": { "type": "git", "url": "https://github.com/pestphp/pest.git", - "reference": "ef120125e036bf84c9e46a9e62219702f5b92e16" + "reference": "d0ff2c8ec294b7aa7fcb0f3ddc4fdec864234646" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pestphp/pest/zipball/ef120125e036bf84c9e46a9e62219702f5b92e16", - "reference": "ef120125e036bf84c9e46a9e62219702f5b92e16", + "url": "https://api.github.com/repos/pestphp/pest/zipball/d0ff2c8ec294b7aa7fcb0f3ddc4fdec864234646", + "reference": "d0ff2c8ec294b7aa7fcb0f3ddc4fdec864234646", "shasum": "" }, "require": { "brianium/paratest": "^7.3.1", - "nunomaduro/collision": "^7.10.0|^8.1.1", + "nunomaduro/collision": "^7.10.0|^8.3.0", "nunomaduro/termwind": "^1.15.1|^2.0.1", "pestphp/pest-plugin": "^2.1.1", "pestphp/pest-plugin-arch": "^2.7.0", @@ -3162,8 +3162,8 @@ }, "require-dev": { "pestphp/pest-dev-tools": "^2.16.0", - "pestphp/pest-plugin-type-coverage": "^2.8.4", - "symfony/process": "^6.4.0|^7.1.1" + "pestphp/pest-plugin-type-coverage": "^2.8.5", + "symfony/process": "^6.4.0|^7.1.3" }, "bin": [ "bin/pest" @@ -3226,7 +3226,7 @@ ], "support": { "issues": "https://github.com/pestphp/pest/issues", - "source": "https://github.com/pestphp/pest/tree/v2.34.9" + "source": "https://github.com/pestphp/pest/tree/v2.35.0" }, "funding": [ { @@ -3238,7 +3238,7 @@ "type": "github" } ], - "time": "2024-07-11T08:36:26+00:00" + "time": "2024-08-02T10:57:29+00:00" }, { "name": "pestphp/pest-plugin", @@ -3383,26 +3383,26 @@ }, { "name": "pestphp/pest-plugin-type-coverage", - "version": "v2.8.4", + "version": "v2.8.5", "source": { "type": "git", "url": "https://github.com/pestphp/pest-plugin-type-coverage.git", - "reference": "ce599efae7c2493e300960cb9c697a9bdd15c44e" + "reference": "147f8b6d5dc180a756aa694d34f606050b823c71" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pestphp/pest-plugin-type-coverage/zipball/ce599efae7c2493e300960cb9c697a9bdd15c44e", - "reference": "ce599efae7c2493e300960cb9c697a9bdd15c44e", + "url": "https://api.github.com/repos/pestphp/pest-plugin-type-coverage/zipball/147f8b6d5dc180a756aa694d34f606050b823c71", + "reference": "147f8b6d5dc180a756aa694d34f606050b823c71", "shasum": "" }, "require": { "pestphp/pest-plugin": "^2.1.1", "php": "^8.1", - "phpstan/phpstan": "^1.11.6", + "phpstan/phpstan": "^1.11.8", "tomasvotruba/type-coverage": "^0.2.8" }, "require-dev": { - "pestphp/pest": "^2.34.8", + "pestphp/pest": "^2.34.9", "pestphp/pest-dev-tools": "^2.16.0" }, "type": "library", @@ -3436,7 +3436,7 @@ ], "support": { "issues": "https://github.com/pestphp/pest-plugin-type-coverage/issues", - "source": "https://github.com/pestphp/pest-plugin-type-coverage/tree/v2.8.4" + "source": "https://github.com/pestphp/pest-plugin-type-coverage/tree/v2.8.5" }, "funding": [ { @@ -3452,7 +3452,7 @@ "type": "patreon" } ], - "time": "2024-07-01T17:18:50+00:00" + "time": "2024-07-24T12:09:30+00:00" }, { "name": "phar-io/manifest", @@ -3965,16 +3965,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.11.7", + "version": "1.11.10", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "52d2bbfdcae7f895915629e4694e9497d0f8e28d" + "reference": "640410b32995914bde3eed26fa89552f9c2c082f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/52d2bbfdcae7f895915629e4694e9497d0f8e28d", - "reference": "52d2bbfdcae7f895915629e4694e9497d0f8e28d", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/640410b32995914bde3eed26fa89552f9c2c082f", + "reference": "640410b32995914bde3eed26fa89552f9c2c082f", "shasum": "" }, "require": { @@ -4019,7 +4019,7 @@ "type": "github" } ], - "time": "2024-07-06T11:17:41+00:00" + "time": "2024-08-08T09:02:50+00:00" }, { "name": "phpunit/php-code-coverage", @@ -5998,16 +5998,16 @@ }, { "name": "spatie/backtrace", - "version": "1.6.1", + "version": "1.6.2", "source": { "type": "git", "url": "https://github.com/spatie/backtrace.git", - "reference": "8373b9d51638292e3bfd736a9c19a654111b4a23" + "reference": "1a9a145b044677ae3424693f7b06479fc8c137a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/backtrace/zipball/8373b9d51638292e3bfd736a9c19a654111b4a23", - "reference": "8373b9d51638292e3bfd736a9c19a654111b4a23", + "url": "https://api.github.com/repos/spatie/backtrace/zipball/1a9a145b044677ae3424693f7b06479fc8c137a9", + "reference": "1a9a145b044677ae3424693f7b06479fc8c137a9", "shasum": "" }, "require": { @@ -6045,7 +6045,7 @@ "spatie" ], "support": { - "source": "https://github.com/spatie/backtrace/tree/1.6.1" + "source": "https://github.com/spatie/backtrace/tree/1.6.2" }, "funding": [ { @@ -6057,7 +6057,7 @@ "type": "other" } ], - "time": "2024-04-24T13:22:11+00:00" + "time": "2024-07-22T08:21:24+00:00" }, { "name": "spatie/macroable", @@ -6270,16 +6270,16 @@ }, { "name": "symfony/console", - "version": "v7.1.2", + "version": "v7.1.3", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "0aa29ca177f432ab68533432db0de059f39c92ae" + "reference": "cb1dcb30ebc7005c29864ee78adb47b5fb7c3cd9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/0aa29ca177f432ab68533432db0de059f39c92ae", - "reference": "0aa29ca177f432ab68533432db0de059f39c92ae", + "url": "https://api.github.com/repos/symfony/console/zipball/cb1dcb30ebc7005c29864ee78adb47b5fb7c3cd9", + "reference": "cb1dcb30ebc7005c29864ee78adb47b5fb7c3cd9", "shasum": "" }, "require": { @@ -6343,7 +6343,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v7.1.2" + "source": "https://github.com/symfony/console/tree/v7.1.3" }, "funding": [ { @@ -6359,7 +6359,7 @@ "type": "tidelift" } ], - "time": "2024-06-28T10:03:55+00:00" + "time": "2024-07-26T12:41:01+00:00" }, { "name": "symfony/deprecation-contracts", @@ -6430,16 +6430,16 @@ }, { "name": "symfony/error-handler", - "version": "v7.1.2", + "version": "v7.1.3", "source": { "type": "git", "url": "https://github.com/symfony/error-handler.git", - "reference": "2412d3dddb5c9ea51a39cfbff1c565fc9844ca32" + "reference": "432bb369952795c61ca1def65e078c4a80dad13c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/error-handler/zipball/2412d3dddb5c9ea51a39cfbff1c565fc9844ca32", - "reference": "2412d3dddb5c9ea51a39cfbff1c565fc9844ca32", + "url": "https://api.github.com/repos/symfony/error-handler/zipball/432bb369952795c61ca1def65e078c4a80dad13c", + "reference": "432bb369952795c61ca1def65e078c4a80dad13c", "shasum": "" }, "require": { @@ -6485,7 +6485,7 @@ "description": "Provides tools to manage errors and ease debugging PHP code", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/error-handler/tree/v7.1.2" + "source": "https://github.com/symfony/error-handler/tree/v7.1.3" }, "funding": [ { @@ -6501,7 +6501,7 @@ "type": "tidelift" } ], - "time": "2024-06-25T19:55:06+00:00" + "time": "2024-07-26T13:02:51+00:00" }, { "name": "symfony/event-dispatcher", @@ -6661,16 +6661,16 @@ }, { "name": "symfony/finder", - "version": "v7.1.1", + "version": "v7.1.3", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "fbb0ba67688b780efbc886c1a0a0948dcf7205d6" + "reference": "717c6329886f32dc65e27461f80f2a465412fdca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/fbb0ba67688b780efbc886c1a0a0948dcf7205d6", - "reference": "fbb0ba67688b780efbc886c1a0a0948dcf7205d6", + "url": "https://api.github.com/repos/symfony/finder/zipball/717c6329886f32dc65e27461f80f2a465412fdca", + "reference": "717c6329886f32dc65e27461f80f2a465412fdca", "shasum": "" }, "require": { @@ -6705,7 +6705,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v7.1.1" + "source": "https://github.com/symfony/finder/tree/v7.1.3" }, "funding": [ { @@ -6721,20 +6721,20 @@ "type": "tidelift" } ], - "time": "2024-05-31T14:57:53+00:00" + "time": "2024-07-24T07:08:44+00:00" }, { "name": "symfony/http-foundation", - "version": "v7.1.1", + "version": "v7.1.3", "source": { "type": "git", "url": "https://github.com/symfony/http-foundation.git", - "reference": "74d171d5b6a1d9e4bfee09a41937c17a7536acfa" + "reference": "f602d5c17d1fa02f8019ace2687d9d136b7f4a1a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-foundation/zipball/74d171d5b6a1d9e4bfee09a41937c17a7536acfa", - "reference": "74d171d5b6a1d9e4bfee09a41937c17a7536acfa", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/f602d5c17d1fa02f8019ace2687d9d136b7f4a1a", + "reference": "f602d5c17d1fa02f8019ace2687d9d136b7f4a1a", "shasum": "" }, "require": { @@ -6782,7 +6782,7 @@ "description": "Defines an object-oriented layer for the HTTP specification", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/http-foundation/tree/v7.1.1" + "source": "https://github.com/symfony/http-foundation/tree/v7.1.3" }, "funding": [ { @@ -6798,20 +6798,20 @@ "type": "tidelift" } ], - "time": "2024-05-31T14:57:53+00:00" + "time": "2024-07-26T12:41:01+00:00" }, { "name": "symfony/http-kernel", - "version": "v7.1.2", + "version": "v7.1.3", "source": { "type": "git", "url": "https://github.com/symfony/http-kernel.git", - "reference": "ae3fa717db4d41a55d14c2bd92399e37cf5bc0f6" + "reference": "db9702f3a04cc471ec8c70e881825db26ac5f186" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-kernel/zipball/ae3fa717db4d41a55d14c2bd92399e37cf5bc0f6", - "reference": "ae3fa717db4d41a55d14c2bd92399e37cf5bc0f6", + "url": "https://api.github.com/repos/symfony/http-kernel/zipball/db9702f3a04cc471ec8c70e881825db26ac5f186", + "reference": "db9702f3a04cc471ec8c70e881825db26ac5f186", "shasum": "" }, "require": { @@ -6896,7 +6896,7 @@ "description": "Provides a structured process for converting a Request into a Response", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/http-kernel/tree/v7.1.2" + "source": "https://github.com/symfony/http-kernel/tree/v7.1.3" }, "funding": [ { @@ -6912,7 +6912,7 @@ "type": "tidelift" } ], - "time": "2024-06-28T13:13:31+00:00" + "time": "2024-07-26T14:58:15+00:00" }, { "name": "symfony/mime", @@ -7558,16 +7558,16 @@ }, { "name": "symfony/process", - "version": "v7.1.1", + "version": "v7.1.3", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "febf90124323a093c7ee06fdb30e765ca3c20028" + "reference": "7f2f542c668ad6c313dc4a5e9c3321f733197eca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/febf90124323a093c7ee06fdb30e765ca3c20028", - "reference": "febf90124323a093c7ee06fdb30e765ca3c20028", + "url": "https://api.github.com/repos/symfony/process/zipball/7f2f542c668ad6c313dc4a5e9c3321f733197eca", + "reference": "7f2f542c668ad6c313dc4a5e9c3321f733197eca", "shasum": "" }, "require": { @@ -7599,7 +7599,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v7.1.1" + "source": "https://github.com/symfony/process/tree/v7.1.3" }, "funding": [ { @@ -7615,7 +7615,7 @@ "type": "tidelift" } ], - "time": "2024-05-31T14:57:53+00:00" + "time": "2024-07-26T12:44:47+00:00" }, { "name": "symfony/service-contracts", @@ -7764,16 +7764,16 @@ }, { "name": "symfony/string", - "version": "v7.1.2", + "version": "v7.1.3", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "14221089ac66cf82e3cf3d1c1da65de305587ff8" + "reference": "ea272a882be7f20cad58d5d78c215001617b7f07" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/14221089ac66cf82e3cf3d1c1da65de305587ff8", - "reference": "14221089ac66cf82e3cf3d1c1da65de305587ff8", + "url": "https://api.github.com/repos/symfony/string/zipball/ea272a882be7f20cad58d5d78c215001617b7f07", + "reference": "ea272a882be7f20cad58d5d78c215001617b7f07", "shasum": "" }, "require": { @@ -7831,7 +7831,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v7.1.2" + "source": "https://github.com/symfony/string/tree/v7.1.3" }, "funding": [ { @@ -7847,20 +7847,20 @@ "type": "tidelift" } ], - "time": "2024-06-28T09:27:18+00:00" + "time": "2024-07-22T10:25:37+00:00" }, { "name": "symfony/translation", - "version": "v7.1.1", + "version": "v7.1.3", "source": { "type": "git", "url": "https://github.com/symfony/translation.git", - "reference": "cf5ae136e124fc7681b34ce9fac9d5b9ae8ceee3" + "reference": "8d5e50c813ba2859a6dfc99a0765c550507934a1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation/zipball/cf5ae136e124fc7681b34ce9fac9d5b9ae8ceee3", - "reference": "cf5ae136e124fc7681b34ce9fac9d5b9ae8ceee3", + "url": "https://api.github.com/repos/symfony/translation/zipball/8d5e50c813ba2859a6dfc99a0765c550507934a1", + "reference": "8d5e50c813ba2859a6dfc99a0765c550507934a1", "shasum": "" }, "require": { @@ -7925,7 +7925,7 @@ "description": "Provides tools to internationalize your application", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/translation/tree/v7.1.1" + "source": "https://github.com/symfony/translation/tree/v7.1.3" }, "funding": [ { @@ -7941,7 +7941,7 @@ "type": "tidelift" } ], - "time": "2024-05-31T14:57:53+00:00" + "time": "2024-07-26T12:41:01+00:00" }, { "name": "symfony/translation-contracts", @@ -8023,16 +8023,16 @@ }, { "name": "symfony/var-dumper", - "version": "v7.1.2", + "version": "v7.1.3", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "5857c57c6b4b86524c08cf4f4bc95327270a816d" + "reference": "86af4617cca75a6e28598f49ae0690f3b9d4591f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/5857c57c6b4b86524c08cf4f4bc95327270a816d", - "reference": "5857c57c6b4b86524c08cf4f4bc95327270a816d", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/86af4617cca75a6e28598f49ae0690f3b9d4591f", + "reference": "86af4617cca75a6e28598f49ae0690f3b9d4591f", "shasum": "" }, "require": { @@ -8086,7 +8086,7 @@ "dump" ], "support": { - "source": "https://github.com/symfony/var-dumper/tree/v7.1.2" + "source": "https://github.com/symfony/var-dumper/tree/v7.1.3" }, "funding": [ { @@ -8102,7 +8102,7 @@ "type": "tidelift" } ], - "time": "2024-06-28T08:00:31+00:00" + "time": "2024-07-26T12:41:01+00:00" }, { "name": "symfony/yaml", diff --git a/index.php b/index.php index 43940ac..65bfb2e 100644 --- a/index.php +++ b/index.php @@ -15,6 +15,9 @@ function nitro(): \Bnomei\Nitro 'sfc' => true, 'dir' => true, ], + 'global' => true, + 'atomic' => true, + 'sleep' => 1_000, // MICROSECONDS with usleep, 1ms 'patch-files-class' => true, 'auto-clean-cache' => true, 'max-dirty-cache' => 512, // write every N changes or on destruct @@ -25,7 +28,7 @@ function nitro(): \Bnomei\Nitro ], ], 'cacheTypes' => [ - 'nitro' => \Bnomei\Nitro\SingleFileCache::class, + 'nitro' => \Bnomei\NitroCache::class, ], 'hooks' => [ 'system.loadPlugins:after' => function () { @@ -41,44 +44,73 @@ function nitro(): \Bnomei\Nitro \Bnomei\Nitro::singleton()->dir()->flush(); } }, + 'system.exception' => function (Throwable $exception) { + // flush and unlock nitro if an exception occurs + \Bnomei\Nitro::singleton()->dir()->flush(); + \Bnomei\Nitro::singleton()->cache()->flush(); + \Bnomei\Nitro::singleton()->cache()->unlock(); + }, ], 'commands' => [ - 'nitro:index' => [ - 'description' => 'Run Nitro Index', + 'nitro:flush' => [ + 'description' => 'Flush Nitro Cache', 'args' => [], 'command' => static function ($cli): void { - $cli->out('Flushing...'); + $cli->out('🚽 Flushing...'); nitro()->flush(); - $cli->out('Indexing...'); - $count = nitro()->modelIndex(); - $cli->out($count.' models indexed.'); + $cli->success('✅ Done.'); - $cli->success('Done.'); + if (function_exists('janitor')) { + janitor()->data($cli->arg('command'), [ + 'status' => 200, + 'message' => 'Nitro Cache flushed.', + ]); + } + }, + ], + 'nitro:unlock' => [ + 'description' => 'Forcibly removes the lock of a Nitro Cache', + 'args' => [], + 'command' => static function ($cli): void { + + $cli->out('🛼 Unlocking...'); + $success = nitro()->cache()->unlock(); + $success ? $cli->success('🔓 Unlocked.') : $cli->error('❌ Failed.'); + + // the flush is necessary as the current instance might not have valid data anymore + $cli->out('🚽 Flushing...'); + nitro()->flush(); + + $cli->success('✅ Done.'); if (function_exists('janitor')) { janitor()->data($cli->arg('command'), [ 'status' => 200, - 'message' => $count.' models indexed.', + 'message' => $success ? 'Unlocked' : 'Failed', ]); } }, ], - 'nitro:flush' => [ - 'description' => 'Flush Nitro Cache', + 'nitro:index' => [ + 'description' => 'Run Nitro Index', 'args' => [], 'command' => static function ($cli): void { - $cli->out('Flushing...'); + $cli->out('🚽 Flushing...'); nitro()->flush(); - $cli->success('Done.'); + $cli->out('🔎 Indexing...'); + $count = nitro()->modelIndex(); + $cli->out($count.' models indexed.'); + + $cli->success('✅ Done.'); if (function_exists('janitor')) { janitor()->data($cli->arg('command'), [ 'status' => 200, - 'message' => 'Nitro Cache flushed.', + 'message' => $count.' models indexed.', ]); } }, diff --git a/tests/NitroTest.php b/tests/NitroTest.php index f3f5e7b..9fffdc8 100644 --- a/tests/NitroTest.php +++ b/tests/NitroTest.php @@ -4,11 +4,6 @@ use Kirby\Filesystem\Dir; use Kirby\Filesystem\F; -beforeEach(function () { - nitro()->flush(); // cleanup - nitro()->cache()->flush(); // cleanup -}); - it('can has an singleton', function () { $nitro = Nitro::singleton(); expect($nitro)->toBeInstanceOf(Nitro::class); @@ -77,7 +72,7 @@ $cache = nitro()->cache(); $cache->set('test', 'value'); $cache->set('test', function () { - throw new \Bnomei\Nitro\AbortCachingExeption(); + throw new \Bnomei\Nitro\AbortCachingExeption; }); expect($cache->get('test'))->toBe('value'); @@ -176,14 +171,15 @@ it('can flush the dir cache', function () { nitro()->modelIndex(); $di = nitro()->dir(); + $di->set('test', []); // make it dirty $di->write(); // force now, not on destruct - expect(Dir::files($di->cacheDir()))->toHaveCount(1) + expect(F::exists($di->file()))->toBeTrue() ->and($di->write())->toBeFalse(); $di->flush(); - expect(Dir::files($di->cacheDir()))->toHaveCount(0); + expect(F::exists($di->file()))->toBeFalse(); }); it('can serialize even null values', function () { @@ -192,8 +188,7 @@ $value = $cache->get('null'); - expect($value)->toBeNull() - ->and($cache->count())->toBe(1); + expect($value)->toBeNull(); }); it('will update the model cache if the model is updated', function () { @@ -218,6 +213,10 @@ it('will update the model cache if the model is deleted', function () { $home = page('home'); kirby()->impersonate('kirby'); + + // cleanup + kirby()->page('home/test')?->delete(true); + $page = $home->createChild([ 'slug' => 'test', ]); @@ -230,3 +229,12 @@ expect($cache->count())->toBe($count - 1); }); + +//it('will flush and unlock on exceptions', function () { +// $cache = nitro()->cache(); +// $cache->set('test', 'value'); +// +// expect($cache->get('test'))->toBe('value'); +// +// throw new Exception('test'); +//})->expectException(Exception::class); diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index cd1ef71..c1db7a8 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -8,6 +8,7 @@ return array( 'Bnomei\\ModelWithNitro' => $baseDir . '/classes/ModelWithNitro.php', 'Bnomei\\Nitro' => $baseDir . '/classes/Nitro.php', + 'Bnomei\\NitroCache' => $baseDir . '/classes/NitroCache.php', 'Bnomei\\NitroFile' => $baseDir . '/classes/NitroFile.php', 'Bnomei\\NitroPage' => $baseDir . '/classes/NitroPage.php', 'Bnomei\\NitroUser' => $baseDir . '/classes/NitroUser.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 5996db9..243b5ca 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -31,6 +31,7 @@ class ComposerStaticInit0eeb079738a6a917b8e643d59e53f8d6 public static $classMap = array ( 'Bnomei\\ModelWithNitro' => __DIR__ . '/../..' . '/classes/ModelWithNitro.php', 'Bnomei\\Nitro' => __DIR__ . '/../..' . '/classes/Nitro.php', + 'Bnomei\\NitroCache' => __DIR__ . '/../..' . '/classes/NitroCache.php', 'Bnomei\\NitroFile' => __DIR__ . '/../..' . '/classes/NitroFile.php', 'Bnomei\\NitroPage' => __DIR__ . '/../..' . '/classes/NitroPage.php', 'Bnomei\\NitroUser' => __DIR__ . '/../..' . '/classes/NitroUser.php', diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 33a3459..8f6c67e 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -1,8 +1,8 @@ array( 'name' => 'bnomei/kirby-nitro', - 'pretty_version' => '1.1.3', - 'version' => '1.1.3.0', + 'pretty_version' => '2.0.0', + 'version' => '2.0.0.0', 'reference' => null, 'type' => 'kirby-plugin', 'install_path' => __DIR__ . '/../../', @@ -11,8 +11,8 @@ ), 'versions' => array( 'bnomei/kirby-nitro' => array( - 'pretty_version' => '1.1.3', - 'version' => '1.1.3.0', + 'pretty_version' => '2.0.0', + 'version' => '2.0.0.0', 'reference' => null, 'type' => 'kirby-plugin', 'install_path' => __DIR__ . '/../../',