Skip to content

Commit

Permalink
Merge pull request #72 from TheDragonCode/3.x
Browse files Browse the repository at this point in the history
Added mention of the possibility of using stdClass when getting TTL
  • Loading branch information
andrey-helldar committed Jun 27, 2023
2 parents 327a935 + 60e32f3 commit 0ce40e9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 2 additions & 0 deletions config/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
// App\Models\News::class => 3600,
// App\Services\Custom::class => 1800,
//
// 'stdClass' => 600,
//
// 'foo' => 300,
// 'bar' => 600,
],
Expand Down
3 changes: 3 additions & 0 deletions tests/Support/TtlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,6 +53,8 @@ protected function setConfig($app): void
CustomObject::class => 300,
DragonCodeArrayable::class => 400,

stdClass::class => 600,

'custom' => 600,
]);
}
Expand Down

0 comments on commit 0ce40e9

Please sign in to comment.