Skip to content

Commit 60e32f3

Browse files
Added mention of the possibility of using stdClass when getting TTL
1 parent 4086dec commit 60e32f3

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,13 @@ use Tests\Fixtures\Simple\CustomObject;
297297
Cache::make()->ttl(CustomObject::class);
298298
Cache::make()->ttl(new CustomObject());
299299
Cache::make()->ttl('custom_key');
300+
Cache::make()->ttl((object) ['foo' => 'Foo']);
300301

301302
// You can also specify that these values are in seconds, not minutes:
302303
Cache::make()->ttl(CustomObject::class, false);
303304
Cache::make()->ttl(new CustomObject(), false);
304305
Cache::make()->ttl('custom_key', false);
306+
Cache::make()->ttl((object) ['foo' => 'Foo'], false);
305307
```
306308

307309
If the value is not found, the [default value](config/cache.php) will be taken, which you can also override in the [configuration file](config/cache.php).

config/cache.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
// App\Models\News::class => 3600,
1111
// App\Services\Custom::class => 1800,
1212
//
13+
// 'stdClass' => 600,
14+
//
1315
// 'foo' => 300,
1416
// 'bar' => 600,
1517
],

tests/Support/TtlTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ public function testObjectAsObject()
8888

8989
$this->assertSame(216000, Ttl::fromMinutes(new IlluminateArrayable()));
9090
$this->assertSame(3600, Ttl::fromSeconds(new IlluminateArrayable()));
91+
92+
$this->assertSame(36000, Ttl::fromMinutes((object) ['foo' => 'Foo']));
93+
$this->assertSame(600, Ttl::fromSeconds((object) ['foo' => 'Foo']));
9194
}
9295

9396
public function testContract()

tests/TestCase.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use DragonCode\Cache\ServiceProvider;
88
use DragonCode\Cache\Services\Cache;
99
use Orchestra\Testbench\TestCase as BaseTestCase;
10+
use stdClass;
1011
use Tests\Concerns\RefreshCache;
1112
use Tests\Concerns\Userable;
1213
use Tests\Fixtures\Simple\CustomObject;
@@ -52,6 +53,8 @@ protected function setConfig($app): void
5253
CustomObject::class => 300,
5354
DragonCodeArrayable::class => 400,
5455

56+
stdClass::class => 600,
57+
5558
'custom' => 600,
5659
]);
5760
}

0 commit comments

Comments
 (0)