From 684d321c00871c67bf90debe001826e90189f8a3 Mon Sep 17 00:00:00 2001 From: Marcus Date: Wed, 3 Feb 2021 16:15:40 +0100 Subject: [PATCH 1/8] Add Flysystem 2 Storage Just upgraded to V2 https://flysystem.thephpleague.com/v2/docs/advanced/upgrade-to-2.0.0/ `use League\Flysystem\AdapterInterface;` => `use League\Flysystem\Local\LocalFilesystemAdapter;` `$this->filesystem->has` => `$this->filesystem->fileExists` `$this->filesystem->put` => `$this->filesystem->write` --- src/Storage/Flysystem2Storage.php | 61 +++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/Storage/Flysystem2Storage.php diff --git a/src/Storage/Flysystem2Storage.php b/src/Storage/Flysystem2Storage.php new file mode 100644 index 00000000..ae2f49e9 --- /dev/null +++ b/src/Storage/Flysystem2Storage.php @@ -0,0 +1,61 @@ +filesystem = new Filesystem($adapter); + } + + /** + * @inheritdoc + */ + public function fetch($key) + { + if ($this->filesystem->fileExists($key)) { + // The file exist, read it! + $data = @unserialize( + $this->filesystem->read($key) + ); + + if ($data instanceof CacheEntry) { + return $data; + } + } + + return; + } + + /** + * @inheritdoc + */ + public function save($key, CacheEntry $data) + { + return $this->filesystem->write($key, serialize($data)); + } + + /** + * {@inheritdoc} + */ + public function delete($key) + { + try { + return $this->filesystem->delete($key); + } catch (FileNotFoundException $ex) { + return true; + } + } +} From dcfe44bcf4ccafa59f888078e176966b2d51ab10 Mon Sep 17 00:00:00 2001 From: Marcus Date: Wed, 3 Feb 2021 16:17:41 +0100 Subject: [PATCH 2/8] Update Readme.md how to use Flysystem 2 --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 8edcda7f..f1ef74a4 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,9 @@ $stack->push( ``` ## Flysystem + +for Flysystem 2 change `FlysystemStorage` to `Flysystem2Storage` + ```php [...] use League\Flysystem\Adapter\Local; From 3b7502e89699e6a0e22c72781f013347ea0af566 Mon Sep 17 00:00:00 2001 From: Marcus Date: Wed, 3 Feb 2021 16:22:03 +0100 Subject: [PATCH 3/8] Add Flysystem 2 Example --- README.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f1ef74a4..c6985320 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,6 @@ $stack->push( ## Flysystem -for Flysystem 2 change `FlysystemStorage` to `Flysystem2Storage` ```php [...] @@ -136,6 +135,28 @@ $stack->push( ); ``` +for Flysystem 2 + +```php +[...] +use League\Flysystem\Local\LocalFilesystemAdapter; +use Kevinrob\GuzzleCache\Strategy\PrivateCacheStrategy; +use Kevinrob\GuzzleCache\Storage\Flysystem2Storage; + +[...] + +$stack->push( + new CacheMiddleware( + new PrivateCacheStrategy( + new Flysystem2Storage( + new LocalFilesystemAdapter('/path/to/cache') + ) + ) + ), + 'cache' +); +``` + ## WordPress Object Cache ```php [...] From b7e04569a09c7968633c4bc87571fe0e09e66b78 Mon Sep 17 00:00:00 2001 From: Marcus Date: Sat, 26 Jun 2021 14:56:09 +0200 Subject: [PATCH 4/8] Use `FilesystemAdapter` --- src/Storage/Flysystem2Storage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Storage/Flysystem2Storage.php b/src/Storage/Flysystem2Storage.php index ae2f49e9..c2f5d7f6 100644 --- a/src/Storage/Flysystem2Storage.php +++ b/src/Storage/Flysystem2Storage.php @@ -3,7 +3,7 @@ namespace Kevinrob\GuzzleCache\Storage; use Kevinrob\GuzzleCache\CacheEntry; -use League\Flysystem\Local\LocalFilesystemAdapter; +use League\Flysystem\FilesystemAdapter; use League\Flysystem\Filesystem; use League\Flysystem\FileNotFoundException; @@ -15,7 +15,7 @@ class Flysystem2Storage implements CacheStorageInterface */ protected $filesystem; - public function __construct(LocalFilesystemAdapter $adapter) + public function __construct(FilesystemAdapter $adapter) { $this->filesystem = new Filesystem($adapter); } From fdc6039f195bc0e97dfc660bc51bb461c3fc0d75 Mon Sep 17 00:00:00 2001 From: Marcus Date: Sat, 26 Jun 2021 14:59:35 +0200 Subject: [PATCH 5/8] Add Flystorage 1 Heading --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c6985320..b0e293c2 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,7 @@ $stack->push( ## Flysystem +for Flysystem 1 ```php [...] From 8b6eed5623fb4125a7c7c8d5f0f0dcc3465d49a0 Mon Sep 17 00:00:00 2001 From: Marcus Date: Tue, 6 Jul 2021 11:04:40 +0200 Subject: [PATCH 6/8] Correct Capitalization --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b0e293c2..42f0621a 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ $stack->push( ## Flysystem -for Flysystem 1 +For Flysystem 1 ```php [...] @@ -136,7 +136,7 @@ $stack->push( ); ``` -for Flysystem 2 +For Flysystem 2 ```php [...] From ef74fb6d462f8f664d54d79ba1686d97dce1d1c3 Mon Sep 17 00:00:00 2001 From: Marcus Date: Wed, 14 Jul 2021 22:22:26 +0200 Subject: [PATCH 7/8] Add Test For Flysystem2Storage --- tests/PrivateCacheTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/PrivateCacheTest.php b/tests/PrivateCacheTest.php index 5be441fc..510930ff 100644 --- a/tests/PrivateCacheTest.php +++ b/tests/PrivateCacheTest.php @@ -14,11 +14,13 @@ use Kevinrob\GuzzleCache\Storage\CompressedDoctrineCacheStorage; use Kevinrob\GuzzleCache\Storage\DoctrineCacheStorage; use Kevinrob\GuzzleCache\Storage\FlysystemStorage; +use Kevinrob\GuzzleCache\Storage\Flysystem2Storage; use Kevinrob\GuzzleCache\Storage\Psr6CacheStorage; use Kevinrob\GuzzleCache\Storage\Psr16CacheStorage; use Kevinrob\GuzzleCache\Storage\VolatileRuntimeStorage; use Kevinrob\GuzzleCache\Strategy\PrivateCacheStrategy; use League\Flysystem\Adapter\Local; +use League\Flysystem\Local\LocalFilesystemAdapter; use PHPUnit\Framework\TestCase; class PrivateCacheTest extends TestCase @@ -33,6 +35,7 @@ public function testCacheProvider() new DoctrineCacheStorage(new FilesystemCache($TMP_DIR)), new DoctrineCacheStorage(new PhpFileCache($TMP_DIR)), new FlysystemStorage(new Local($TMP_DIR)), + new Flysystem2Storage(new LocalFilesystemAdapter($TMP_DIR)), new Psr6CacheStorage(new ArrayCachePool()), new Psr16CacheStorage(new SimpleCacheBridge(new ArrayCachePool())), new CompressedDoctrineCacheStorage(new ArrayCache()), From 44900e5d3bd7ffe39275355014011e0ae90b445a Mon Sep 17 00:00:00 2001 From: Marcus Date: Wed, 14 Jul 2021 22:24:35 +0200 Subject: [PATCH 8/8] Add Test For Flysystem2Storage --- tests/PublicCacheTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/PublicCacheTest.php b/tests/PublicCacheTest.php index b3e92719..982387f5 100644 --- a/tests/PublicCacheTest.php +++ b/tests/PublicCacheTest.php @@ -18,11 +18,13 @@ use Kevinrob\GuzzleCache\Storage\CompressedDoctrineCacheStorage; use Kevinrob\GuzzleCache\Storage\DoctrineCacheStorage; use Kevinrob\GuzzleCache\Storage\FlysystemStorage; +use Kevinrob\GuzzleCache\Storage\Flysystem2Storage; use Kevinrob\GuzzleCache\Storage\Psr6CacheStorage; use Kevinrob\GuzzleCache\Storage\Psr16CacheStorage; use Kevinrob\GuzzleCache\Storage\VolatileRuntimeStorage; use Kevinrob\GuzzleCache\Strategy\PublicCacheStrategy; use League\Flysystem\Adapter\Local; +use League\Flysystem\Local\LocalFilesystemAdapter; use Psr\Http\Message\RequestInterface; use PHPUnit\Framework\TestCase; @@ -101,6 +103,7 @@ public function testCacheProvider() new DoctrineCacheStorage(new FilesystemCache($TMP_DIR)), new DoctrineCacheStorage(new PhpFileCache($TMP_DIR)), new FlysystemStorage(new Local($TMP_DIR)), + new Flysystem2Storage(new LocalFilesystemAdapter($TMP_DIR)), new Psr6CacheStorage(new ArrayCachePool()), new Psr16CacheStorage(new SimpleCacheBridge(new ArrayCachePool())), new CompressedDoctrineCacheStorage(new ArrayCache()),