diff --git a/README.md b/README.md index a49205c..97ce5e0 100644 --- a/README.md +++ b/README.md @@ -297,11 +297,13 @@ use Tests\Fixtures\Simple\CustomObject; Cache::make()->ttl(CustomObject::class); Cache::make()->ttl(new CustomObject()); Cache::make()->ttl('custom_key'); +Cache::make()->ttl((object) ['foo' => 'Foo']); // You can also specify that these values are in seconds, not minutes: Cache::make()->ttl(CustomObject::class, false); Cache::make()->ttl(new CustomObject(), false); Cache::make()->ttl('custom_key', false); +Cache::make()->ttl((object) ['foo' => 'Foo'], false); ``` 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). diff --git a/config/cache.php b/config/cache.php index 337cb83..fbbdeed 100644 --- a/config/cache.php +++ b/config/cache.php @@ -10,6 +10,8 @@ // App\Models\News::class => 3600, // App\Services\Custom::class => 1800, // + // 'stdClass' => 600, + // // 'foo' => 300, // 'bar' => 600, ], diff --git a/tests/Support/TtlTest.php b/tests/Support/TtlTest.php index 22ef607..7756f6f 100644 --- a/tests/Support/TtlTest.php +++ b/tests/Support/TtlTest.php @@ -88,6 +88,9 @@ public function testObjectAsObject() $this->assertSame(216000, Ttl::fromMinutes(new IlluminateArrayable())); $this->assertSame(3600, Ttl::fromSeconds(new IlluminateArrayable())); + + $this->assertSame(36000, Ttl::fromMinutes((object) ['foo' => 'Foo'])); + $this->assertSame(600, Ttl::fromSeconds((object) ['foo' => 'Foo'])); } public function testContract() diff --git a/tests/TestCase.php b/tests/TestCase.php index 459e13d..0ab35e2 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -7,6 +7,7 @@ use DragonCode\Cache\ServiceProvider; use DragonCode\Cache\Services\Cache; use Orchestra\Testbench\TestCase as BaseTestCase; +use stdClass; use Tests\Concerns\RefreshCache; use Tests\Concerns\Userable; use Tests\Fixtures\Simple\CustomObject; @@ -52,6 +53,8 @@ protected function setConfig($app): void CustomObject::class => 300, DragonCodeArrayable::class => 400, + stdClass::class => 600, + 'custom' => 600, ]); }