Fixed bug that the value of ttl will be converted to 0 when you don't set it. (#3301)

Co-authored-by: 李铭昕 <715557344@qq.com>
This commit is contained in:
Alone88 2021-02-24 08:36:57 +08:00 committed by GitHub
parent 4bdf88524f
commit 18b40615f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 4 deletions

View File

@ -1,5 +1,9 @@
# v2.1.8 - TBD
## Fixed
- [#3301](https://github.com/hyperf/hyperf/pull/3301) Fixed bug that the value of ttl will be converted to 0 when you don't set it for `hyperf/cache`.
# v2.1.7 - 2021-02-22
## Fixed

View File

@ -30,7 +30,7 @@ class CachePut extends AbstractAnnotation
public $value;
/**
* @var int
* @var null|int
*/
public $ttl;
@ -48,7 +48,9 @@ class CachePut extends AbstractAnnotation
public function __construct($value = null)
{
parent::__construct($value);
$this->ttl = (int) $this->ttl;
if ($this->ttl !== null) {
$this->ttl = (int) $this->ttl;
}
$this->offset = (int) $this->offset;
}
}

View File

@ -32,7 +32,7 @@ class Cacheable extends AbstractAnnotation
public $value;
/**
* @var int
* @var null|int
*/
public $ttl;
@ -60,7 +60,9 @@ class Cacheable extends AbstractAnnotation
public function __construct($value = null)
{
parent::__construct($value);
$this->ttl = (int) $this->ttl;
if ($this->ttl !== null) {
$this->ttl = (int) $this->ttl;
}
$this->offset = (int) $this->offset;
}

View File

@ -52,6 +52,22 @@ class AnnotationTest extends TestCase
$this->assertSame('test', $annotation->prefix);
$this->assertSame(3600, $annotation->ttl);
$this->assertSame(100, $annotation->offset);
$annotation = new Cacheable([
'prefix' => 'test',
'ttl' => null,
]);
$this->assertSame('test', $annotation->prefix);
$this->assertSame(null, $annotation->ttl);
$annotation = new CachePut([
'prefix' => 'test',
'ttl' => null,
]);
$this->assertSame('test', $annotation->prefix);
$this->assertSame(null, $annotation->ttl);
}
public function testAnnotationManager()