mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-30 10:47:44 +08:00
Removed useless docs about cache.
Co-authored-by: 李铭昕 <715557344@qq.com>
This commit is contained in:
parent
c9fe4d724f
commit
930ecd2fe9
@ -181,6 +181,8 @@ class UserService
|
||||
|
||||
当设置 `value` 后,框架会根据设置的规则,进行缓存 `KEY` 键命名。如下实例,当 `$user->id = 1` 时,缓存 `KEY` 为 `c:userBook:_1`
|
||||
|
||||
> 此配置也同样支持下述其他类型缓存注解
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
@ -233,31 +235,6 @@ class UserService
|
||||
}
|
||||
```
|
||||
|
||||
当设置 `value` 后,框架会根据设置的规则,进行缓存 `KEY` 键命名。如下实例,当 `$user->id = 1` 时,缓存 `KEY` 为 `c:userBook:_1`
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Models\User;
|
||||
use Hyperf\Cache\Annotation\Cacheable;
|
||||
|
||||
class UserBookService
|
||||
{
|
||||
#[Cacheable(prefix: "userBook", ttl: 6666, value: "_#{user.id}")]
|
||||
public function userBook(User $user): array
|
||||
{
|
||||
return [
|
||||
'book' => $user->book->toArray(),
|
||||
'uuid' => $this->unique(),
|
||||
];
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### CachePut
|
||||
|
||||
`CachePut` 不同于 `Cacheable`,它每次调用都会执行函数体,然后再对缓存进行重写。所以当我们想更新缓存时,可以调用相关方法。
|
||||
|
@ -233,31 +233,6 @@ class UserService
|
||||
}
|
||||
```
|
||||
|
||||
當設置 `value` 後,框架會根據設置的規則,進行緩存 `KEY` 鍵命名。如下實例,當 `$user->id = 1` 時,緩存 `KEY` 為 `c:userBook:_1`
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Models\User;
|
||||
use Hyperf\Cache\Annotation\Cacheable;
|
||||
|
||||
class UserBookService
|
||||
{
|
||||
#[Cacheable(prefix: "userBook", ttl: 6666, value: "_#{user.id}")]
|
||||
public function userBook(User $user): array
|
||||
{
|
||||
return [
|
||||
'book' => $user->book->toArray(),
|
||||
'uuid' => $this->unique(),
|
||||
];
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### CachePut
|
||||
|
||||
`CachePut` 不同於 `Cacheable`,它每次調用都會執行函數體,然後再對緩存進行重寫。所以當我們想更新緩存時,可以調用相關方法。
|
||||
|
@ -233,31 +233,6 @@ class UserService
|
||||
}
|
||||
```
|
||||
|
||||
當設定 `value` 後,框架會根據設定的規則,進行快取 `KEY` 鍵命名。如下例項,當 `$user->id = 1` 時,快取 `KEY` 為 `c:userBook:_1`
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Models\User;
|
||||
use Hyperf\Cache\Annotation\Cacheable;
|
||||
|
||||
class UserBookService
|
||||
{
|
||||
#[Cacheable(prefix: "userBook", ttl: 6666, value: "_#{user.id}")]
|
||||
public function userBook(User $user): array
|
||||
{
|
||||
return [
|
||||
'book' => $user->book->toArray(),
|
||||
'uuid' => $this->unique(),
|
||||
];
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### CachePut
|
||||
|
||||
`CachePut` 不同於 `Cacheable`,它每次呼叫都會執行函式體,然後再對快取進行重寫。所以當我們想更新快取時,可以呼叫相關方法。
|
||||
|
Loading…
Reference in New Issue
Block a user