mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-30 02:37:58 +08:00
Update docs and translate
This commit is contained in:
parent
913746a0bc
commit
4c34571889
@ -204,6 +204,60 @@ class UserBookService
|
||||
}
|
||||
```
|
||||
|
||||
### CacheAhead
|
||||
|
||||
例如以下配置,緩存前綴為 `user`, 超時時間為 `7200`, 生成對應緩存 KEY 為 `c:user:1`,並且在 7200 - 600 秒的時候,每 10 秒進行一次緩存初始化,直到首次成功。
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Models\User;
|
||||
use Hyperf\Cache\Annotation\CacheAhead;
|
||||
|
||||
class UserService
|
||||
{
|
||||
#[CacheAhead(prefix: "user", ttl: 7200, aheadSeconds: 600, lockSeconds: 10)]
|
||||
public function user(int $id): array
|
||||
{
|
||||
$user = User::query()->find($id);
|
||||
|
||||
return [
|
||||
'user' => $user->toArray(),
|
||||
'uuid' => $this->unique(),
|
||||
];
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
當設置 `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`,它每次調用都會執行函數體,然後再對緩存進行重寫。所以當我們想更新緩存時,可以調用相關方法。
|
||||
|
@ -151,7 +151,7 @@ $result = $redis->keys('*');
|
||||
|
||||
## 哨兵模式
|
||||
|
||||
開啟哨兵模式可以在`.env`或`redis.php`配置文件中修改如下
|
||||
開啟哨兵模式可以在`.env`或 `redis.php` 配置文件中修改如下
|
||||
|
||||
多個哨兵節點使用`;`分割
|
||||
|
||||
|
@ -4,8 +4,8 @@
|
||||
|
||||
| 版本 | 狀態 | 積極支持截止時間 | 安全維護截止時間 | 發佈或預計發佈時間 |
|
||||
| ---- |----------------|------------|------------|---------------|
|
||||
| 3.0 | 研發中 (RC13 已發佈) | 2023-06-30 | 2023-12-31 | 大概 2022-12-31 |
|
||||
| 2.2 | 安全維護 | 2022-06-20 | 2023-06-30 | 2021-07-19 |
|
||||
| 3.0 | 研發中 (RC17 已發佈) | 2023-06-30 | 2023-12-31 | 大概 2022-12-31 |
|
||||
| 2.2 | 安全維護 | 2022-06-20 | 2023-06-30 | 2021-07-19 |
|
||||
| 2.1 | 停止維護 | 2021-06-30 | 2021-12-31 | 2020-12-28 |
|
||||
| 2.0 | 停止維護 | 2020-12-28 | 2021-06-30 | 2020-06-22 |
|
||||
| 1.1 | 停止維護 | 2020-06-23 | 2020-12-31 | 2019-10-08 |
|
||||
|
@ -204,6 +204,60 @@ class UserBookService
|
||||
}
|
||||
```
|
||||
|
||||
### CacheAhead
|
||||
|
||||
例如以下配置,快取字首為 `user`, 超時時間為 `7200`, 生成對應快取 KEY 為 `c:user:1`,並且在 7200 - 600 秒的時候,每 10 秒進行一次快取初始化,直到首次成功。
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Models\User;
|
||||
use Hyperf\Cache\Annotation\CacheAhead;
|
||||
|
||||
class UserService
|
||||
{
|
||||
#[CacheAhead(prefix: "user", ttl: 7200, aheadSeconds: 600, lockSeconds: 10)]
|
||||
public function user(int $id): array
|
||||
{
|
||||
$user = User::query()->find($id);
|
||||
|
||||
return [
|
||||
'user' => $user->toArray(),
|
||||
'uuid' => $this->unique(),
|
||||
];
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
當設定 `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`,它每次呼叫都會執行函式體,然後再對快取進行重寫。所以當我們想更新快取時,可以呼叫相關方法。
|
||||
|
@ -151,7 +151,7 @@ $result = $redis->keys('*');
|
||||
|
||||
## 哨兵模式
|
||||
|
||||
開啟哨兵模式可以在`.env`或`redis.php`配置檔案中修改如下
|
||||
開啟哨兵模式可以在`.env`或 `redis.php` 配置檔案中修改如下
|
||||
|
||||
多個哨兵節點使用`;`分割
|
||||
|
||||
|
@ -4,8 +4,8 @@
|
||||
|
||||
| 版本 | 狀態 | 積極支援截止時間 | 安全維護截止時間 | 釋出或預計釋出時間 |
|
||||
| ---- |----------------|------------|------------|---------------|
|
||||
| 3.0 | 研發中 (RC13 已釋出) | 2023-06-30 | 2023-12-31 | 大概 2022-12-31 |
|
||||
| 2.2 | 安全維護 | 2022-06-20 | 2023-06-30 | 2021-07-19 |
|
||||
| 3.0 | 研發中 (RC17 已釋出) | 2023-06-30 | 2023-12-31 | 大概 2022-12-31 |
|
||||
| 2.2 | 安全維護 | 2022-06-20 | 2023-06-30 | 2021-07-19 |
|
||||
| 2.1 | 停止維護 | 2021-06-30 | 2021-12-31 | 2020-12-28 |
|
||||
| 2.0 | 停止維護 | 2020-12-28 | 2021-06-30 | 2020-06-22 |
|
||||
| 1.1 | 停止維護 | 2020-06-23 | 2020-12-31 | 2019-10-08 |
|
||||
|
Loading…
Reference in New Issue
Block a user