Skip to content

Commit

Permalink
Merge pull request #76 from TheDragonCode/3.x
Browse files Browse the repository at this point in the history
Added `Cache::rememberForever` method
  • Loading branch information
andrey-helldar authored Nov 14, 2023
2 parents 520d096 + 2ec8662 commit d41405c
Show file tree
Hide file tree
Showing 57 changed files with 525 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup Redis
uses: zhulik/[email protected]
uses: shogo82148/actions-setup-redis@v1

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
],
"require": {
"php": "^8.0",
"dragon-code/contracts": "^2.16",
"dragon-code/contracts": "^2.21",
"dragon-code/support": "^6.11.3",
"illuminate/support": ">=6.0 <11.0"
},
Expand Down
3 changes: 0 additions & 3 deletions src/Concerns/Call.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ trait Call
{
use Arrayable;

/**
* @param mixed $callback
*/
protected function call(mixed $callback = null): mixed
{
return $this->isCallable($callback) ? $callback() : $callback;
Expand Down
5 changes: 5 additions & 0 deletions src/Services/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public function remember(mixed $value): mixed
return $this->manager()->remember($this->getKey(), $value, $this->ttl);
}

public function rememberForever(mixed $value): mixed
{
return $this->manager()->rememberForever($this->getKey(), $value);
}

public function forget(): static
{
$this->manager()->forget($this->getKey());
Expand Down
5 changes: 5 additions & 0 deletions src/Services/Storages/Disabled.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public function remember(string $key, $value, int $seconds): mixed
return $this->get($key, $value);
}

public function rememberForever(string $key, $value): mixed
{
return $this->get($key, $value);
}

public function forget(string $key): void {}

public function has(string $key): bool
Expand Down
7 changes: 7 additions & 0 deletions src/Services/Storages/MainStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ public function remember(string $key, $value, int $seconds): mixed
return Cache::remember($key, $seconds, $value);
}

public function rememberForever(string $key, $value): mixed
{
$value = $this->makeCallable($value);

return Cache::rememberForever($key, $value);
}

public function forget(string $key): void
{
Cache::forget($key);
Expand Down
7 changes: 7 additions & 0 deletions src/Services/Storages/TaggedStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ public function remember(string $key, $value, int $seconds): mixed
return $this->cache()->remember($key, $seconds, $value);
}

public function rememberForever(string $key, $value): mixed
{
$value = $this->makeCallable($value);

return $this->cache()->rememberForever($key, $value);
}

public function forget(string $key): void
{
$this->cache()->forget($key);
Expand Down
5 changes: 5 additions & 0 deletions src/Support/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public function remember(string $key, $value, int $seconds): mixed
return $this->instance()->remember($key, $value, $seconds);
}

public function rememberForever(string $key, $value): mixed
{
return $this->instance()->rememberForever($key, $value);
}

public function forget(string $key): void
{
$this->instance()->forget($key);
Expand Down
9 changes: 9 additions & 0 deletions tests/Cache/NotWhen/Arrayables/Many/Arr/DragonCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ public function testRemember()
$this->assertNull($this->cache()->get());
}

public function testRememberForever()
{
$item = new DragonCodeArrayable();

$this->assertSame($item, $this->cache()->rememberForever($item));

$this->assertNull($this->cache()->get());
}

public function testForget()
{
$this->assertNull($this->cache()->get());
Expand Down
9 changes: 9 additions & 0 deletions tests/Cache/NotWhen/Arrayables/Many/Arr/IlluminateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ public function testRemember()
$this->assertNull($this->cache()->get());
}

public function testRememberForever()
{
$item = new IlluminateArrayable();

$this->assertSame($item, $this->cache()->rememberForever($item));

$this->assertNull($this->cache()->get());
}

public function testForget()
{
$this->assertNull($this->cache()->get());
Expand Down
9 changes: 9 additions & 0 deletions tests/Cache/NotWhen/Arrayables/Many/Arr/MixedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ public function testRemember()
$this->assertNull($this->cache()->get());
}

public function testRememberForever()
{
$item = new MixedArrayable();

$this->assertSame($item, $this->cache()->rememberForever($item));

$this->assertNull($this->cache()->get());
}

public function testForget()
{
$this->assertNull($this->cache()->get());
Expand Down
9 changes: 9 additions & 0 deletions tests/Cache/NotWhen/Arrayables/Many/Files/DragonCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ public function testRemember()
$this->assertNull($this->cache()->get());
}

public function testRememberForever()
{
$item = new DragonCodeArrayable();

$this->assertSame($item, $this->cache()->rememberForever($item));

$this->assertNull($this->cache()->get());
}

public function testForget()
{
$this->assertNull($this->cache()->get());
Expand Down
9 changes: 9 additions & 0 deletions tests/Cache/NotWhen/Arrayables/Many/Files/IlluminateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ public function testRemember()
$this->assertNull($this->cache()->get());
}

public function testRememberForever()
{
$item = new IlluminateArrayable();

$this->assertSame($item, $this->cache()->rememberForever($item));

$this->assertNull($this->cache()->get());
}

public function testForget()
{
$this->assertNull($this->cache()->get());
Expand Down
9 changes: 9 additions & 0 deletions tests/Cache/NotWhen/Arrayables/Many/Files/MixedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ public function testRemember()
$this->assertNull($this->cache()->get());
}

public function testRememberForever()
{
$item = new MixedArrayable();

$this->assertSame($item, $this->cache()->rememberForever($item));

$this->assertNull($this->cache()->get());
}

public function testForget()
{
$this->assertNull($this->cache()->get());
Expand Down
13 changes: 13 additions & 0 deletions tests/Cache/NotWhen/Arrayables/Many/Redis/DragonCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ public function testRemember()
$this->assertNull($this->cache(['cache'])->get());
}

public function testRememberForever()
{
$item = new DragonCodeArrayable();

$this->assertSame($item, $this->cache()->rememberForever($item));

$this->assertNull($this->cache()->get());
$this->assertNull($this->cache(['qwerty', 'cache'])->get());

$this->assertNull($this->cache(['qwerty'])->get());
$this->assertNull($this->cache(['cache'])->get());
}

public function testForget()
{
$this->assertNull($this->cache()->get());
Expand Down
13 changes: 13 additions & 0 deletions tests/Cache/NotWhen/Arrayables/Many/Redis/IlluminateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ public function testRemember()
$this->assertNull($this->cache(['cache'])->get());
}

public function testRememberForever()
{
$item = new IlluminateArrayable();

$this->assertSame($item, $this->cache()->rememberForever($item));

$this->assertNull($this->cache()->get());
$this->assertNull($this->cache(['qwerty', 'cache'])->get());

$this->assertNull($this->cache(['qwerty'])->get());
$this->assertNull($this->cache(['cache'])->get());
}

public function testForget()
{
$this->assertNull($this->cache()->get());
Expand Down
13 changes: 13 additions & 0 deletions tests/Cache/NotWhen/Arrayables/Many/Redis/MixedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ public function testRemember()
$this->assertNull($this->cache(['cache'])->get());
}

public function testRememberForever()
{
$item = new MixedArrayable();

$this->assertSame($item, $this->cache()->rememberForever($item));

$this->assertNull($this->cache()->get());
$this->assertNull($this->cache(['qwerty', 'cache'])->get());

$this->assertNull($this->cache(['qwerty'])->get());
$this->assertNull($this->cache(['cache'])->get());
}

public function testForget()
{
$this->assertNull($this->cache()->get());
Expand Down
9 changes: 9 additions & 0 deletions tests/Cache/NotWhen/Arrayables/Simple/Arr/DragonCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ public function testRemember()
$this->assertNull($this->cache()->get());
}

public function testRememberForever()
{
$item = new DragonCodeArrayable();

$this->assertSame($item, $this->cache()->rememberForever($item));

$this->assertNull($this->cache()->get());
}

public function testForget()
{
$this->assertNull($this->cache()->get());
Expand Down
9 changes: 9 additions & 0 deletions tests/Cache/NotWhen/Arrayables/Simple/Arr/IlluminateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ public function testRemember()
$this->assertNull($this->cache()->get());
}

public function testRememberForever()
{
$item = new IlluminateArrayable();

$this->assertSame($item, $this->cache()->rememberForever($item));

$this->assertNull($this->cache()->get());
}

public function testForget()
{
$this->assertNull($this->cache()->get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ public function testRemember()
$this->assertNull($this->cache()->get());
}

public function testRememberForever()
{
$item = new DragonCodeArrayable();

$this->assertSame($item, $this->cache()->rememberForever($item));

$this->assertNull($this->cache()->get());
}

public function testForget()
{
$this->assertNull($this->cache()->get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ public function testRemember()
$this->assertNull($this->cache()->get());
}

public function testRememberForever()
{
$item = new IlluminateArrayable();

$this->assertSame($item, $this->cache()->rememberForever($item));

$this->assertNull($this->cache()->get());
}

public function testForget()
{
$this->assertNull($this->cache()->get());
Expand Down
13 changes: 13 additions & 0 deletions tests/Cache/NotWhen/Arrayables/Simple/Redis/DragonCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ public function testRemember()
$this->assertNull($this->cache(['cache'])->get());
}

public function testRememberForever()
{
$item = new DragonCodeArrayable();

$this->assertSame($item, $this->cache()->rememberForever($item));

$this->assertNull($this->cache()->get());
$this->assertNull($this->cache(['qwerty', 'cache'])->get());

$this->assertNull($this->cache(['qwerty'])->get());
$this->assertNull($this->cache(['cache'])->get());
}

public function testForget()
{
$this->assertNull($this->cache()->get());
Expand Down
13 changes: 13 additions & 0 deletions tests/Cache/NotWhen/Arrayables/Simple/Redis/IlluminateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ public function testRemember()
$this->assertNull($this->cache(['cache'])->get());
}

public function testRememberForever()
{
$item = new IlluminateArrayable();

$this->assertSame($item, $this->cache()->rememberForever($item));

$this->assertNull($this->cache()->get());
$this->assertNull($this->cache(['qwerty', 'cache'])->get());

$this->assertNull($this->cache(['qwerty'])->get());
$this->assertNull($this->cache(['cache'])->get());
}

public function testForget()
{
$this->assertNull($this->cache()->get());
Expand Down
11 changes: 11 additions & 0 deletions tests/Cache/NotWhen/Callables/ArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ public function testRemember()
$this->assertNull($this->cache()->get());
}

public function testRememberForever()
{
$item = function () {
return $this->value;
};

$this->assertSame($this->value, $this->cache()->rememberForever($item));

$this->assertNull($this->cache()->get());
}

public function testForget()
{
$this->assertNull($this->cache()->get());
Expand Down
11 changes: 11 additions & 0 deletions tests/Cache/NotWhen/Callables/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ public function testRemember()
$this->assertNull($this->cache()->get());
}

public function testRememberForever()
{
$item = function () {
return $this->value;
};

$this->assertSame($this->value, $this->cache()->rememberForever($item));

$this->assertNull($this->cache()->get());
}

public function testForget()
{
$this->assertNull($this->cache()->get());
Expand Down
Loading

0 comments on commit d41405c

Please sign in to comment.