From cf5b06636f1a9289618def8ac2ebb246aec4fcbd Mon Sep 17 00:00:00 2001 From: Franck DAKIA Date: Fri, 22 Sep 2023 15:54:41 +0000 Subject: [PATCH 1/3] Change cache method to store --- src/Cache/Cache.php | 4 ++-- tests/Cache/CacheDatabaseTest.php | 2 +- tests/Cache/CacheFilesystemTest.php | 2 +- tests/Cache/CacheRedisTest.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Cache/Cache.php b/src/Cache/Cache.php index 9e51d06f..bf4a4514 100644 --- a/src/Cache/Cache.php +++ b/src/Cache/Cache.php @@ -57,7 +57,7 @@ public static function configure(array $config) static::$config = $config; $store = (array) $config["stores"][$config["default"]]; - return static::cache($store["driver"]); + return static::store($store["driver"]); } /** @@ -80,7 +80,7 @@ public static function getInstance(): CacheAdapterInterface * @param string $driver * @return CacheAdapterInterface */ - public static function cache(string $store): CacheAdapterInterface + public static function store(string $store): CacheAdapterInterface { $stores = static::$config["stores"]; diff --git a/tests/Cache/CacheDatabaseTest.php b/tests/Cache/CacheDatabaseTest.php index c08fdcce..179a1729 100644 --- a/tests/Cache/CacheDatabaseTest.php +++ b/tests/Cache/CacheDatabaseTest.php @@ -23,7 +23,7 @@ public static function setUpBeforeClass(): void )"); Cache::configure($config["cache"]); - Cache::cache("database"); + Cache::store("database"); } public function test_create_cache() diff --git a/tests/Cache/CacheFilesystemTest.php b/tests/Cache/CacheFilesystemTest.php index 2595fca2..d957b2ee 100644 --- a/tests/Cache/CacheFilesystemTest.php +++ b/tests/Cache/CacheFilesystemTest.php @@ -12,7 +12,7 @@ protected function setUp(): void parent::setUp(); $config = TestingConfiguration::getConfig(); Cache::configure($config["cache"]); - Cache::cache("file"); + Cache::store("file"); } public function test_create_cache() diff --git a/tests/Cache/CacheRedisTest.php b/tests/Cache/CacheRedisTest.php index 2e8508c0..d24d8aae 100644 --- a/tests/Cache/CacheRedisTest.php +++ b/tests/Cache/CacheRedisTest.php @@ -12,7 +12,7 @@ protected function setUp(): void parent::setUp(); $config = TestingConfiguration::getConfig(); Cache::configure($config["cache"]); - Cache::cache("redis"); + Cache::store("redis"); } public function test_create_cache() From 63a9e3d12a7d5cfc9b46b15128212e8c23393adc Mon Sep 17 00:00:00 2001 From: Franck DAKIA Date: Fri, 22 Sep 2023 16:20:51 +0000 Subject: [PATCH 2/3] Update cache method --- src/Cache/README.md | 2 +- src/Database/Barry/Relations/HasOne.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Cache/README.md b/src/Cache/README.md index a1229c62..5c4e9f0c 100644 --- a/src/Cache/README.md +++ b/src/Cache/README.md @@ -16,7 +16,7 @@ $content = cache("name"); By specifying the driver: ``` -$content = Cache::cache('redis')->get('name'); +$content = Cache::store('redis')->get('name'); ``` Is very enjoyful api diff --git a/src/Database/Barry/Relations/HasOne.php b/src/Database/Barry/Relations/HasOne.php index 535b4762..1b254719 100644 --- a/src/Database/Barry/Relations/HasOne.php +++ b/src/Database/Barry/Relations/HasOne.php @@ -50,7 +50,7 @@ public function __construct(Model $related, Model $parent, string $foreign_key, public function getResults(): ?Model { $key = $this->query->getTable() . ":hasone:" . $this->related->getTable() . ":" . $this->foreign_key; - $cache = Cache::cache('file')->get($key); + $cache = Cache::store('file')->get($key); if (!is_null($cache)) { $related = new $this->related(); @@ -61,7 +61,7 @@ public function getResults(): ?Model $result = $this->query->first(); if (!is_null($result)) { - Cache::cache('file')->add($key, $result->toArray(), 500); + Cache::store('file')->add($key, $result->toArray(), 60); } return $result; From 43f27ab5cb70016c202272bbb9b6de8c36295e13 Mon Sep 17 00:00:00 2001 From: Franck DAKIA Date: Fri, 22 Sep 2023 16:30:15 +0000 Subject: [PATCH 3/3] Update unity tests --- src/Database/Barry/Relations/BelongsTo.php | 4 ++-- tests/Database/Relation/BelongsToRelationQueryTest.php | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Database/Barry/Relations/BelongsTo.php b/src/Database/Barry/Relations/BelongsTo.php index 6e1ab70d..f48b71fe 100644 --- a/src/Database/Barry/Relations/BelongsTo.php +++ b/src/Database/Barry/Relations/BelongsTo.php @@ -52,7 +52,7 @@ public function __construct( public function getResults(): ?Model { $key = $this->query->getTable() . ":belongsto:" . $this->related->getTable() . ":" . $this->foreign_key; - $cache = Cache::cache('file')->get($key); + $cache = Cache::store('file')->get($key); if (!is_null($cache)) { $related = new $this->related(); @@ -63,7 +63,7 @@ public function getResults(): ?Model $result = $this->query->first(); if (!is_null($result)) { - Cache::cache('file')->add($key, $result->toArray(), 500); + Cache::store('file')->add($key, $result->toArray(), 500); } return $result; diff --git a/tests/Database/Relation/BelongsToRelationQueryTest.php b/tests/Database/Relation/BelongsToRelationQueryTest.php index d983bcb2..d17be65a 100644 --- a/tests/Database/Relation/BelongsToRelationQueryTest.php +++ b/tests/Database/Relation/BelongsToRelationQueryTest.php @@ -2,12 +2,13 @@ namespace Bow\Tests\Database\Relation; +use Bow\Cache\Cache; use Bow\Database\Database; use Bow\Database\Migration\SQLGenerator; use Bow\Tests\Config\TestingConfiguration; -use Bow\Tests\Database\Stubs\MigrationExtendedStub; -use Bow\Tests\Database\Stubs\PetMasterModelStub; use Bow\Tests\Database\Stubs\PetModelStub; +use Bow\Tests\Database\Stubs\PetMasterModelStub; +use Bow\Tests\Database\Stubs\MigrationExtendedStub; class BelongsToRelationQueryTest extends \PHPUnit\Framework\TestCase { @@ -15,6 +16,7 @@ public static function setUpBeforeClass(): void { $config = TestingConfiguration::getConfig(); Database::configure($config["database"]); + Cache::configure($config["cache"]); } public function connectionNames()