Skip to content

Commit

Permalink
Merge pull request #264 from bowphp/feat-integrate-queue-adapters
Browse files Browse the repository at this point in the history
Change cache method to store
  • Loading branch information
papac authored Sep 22, 2023
2 parents c0c7624 + 43f27ab commit c3a2aca
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
}

/**
Expand All @@ -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"];

Expand Down
2 changes: 1 addition & 1 deletion src/Cache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/Database/Barry/Relations/BelongsTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Database/Barry/Relations/HasOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/Cache/CacheDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function setUpBeforeClass(): void
)");

Cache::configure($config["cache"]);
Cache::cache("database");
Cache::store("database");
}

public function test_create_cache()
Expand Down
2 changes: 1 addition & 1 deletion tests/Cache/CacheFilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/Cache/CacheRedisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions tests/Database/Relation/BelongsToRelationQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

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
{
public static function setUpBeforeClass(): void
{
$config = TestingConfiguration::getConfig();
Database::configure($config["database"]);
Cache::configure($config["cache"]);
}

public function connectionNames()
Expand Down

0 comments on commit c3a2aca

Please sign in to comment.