|
|
@@ -655,14 +655,13 @@ class PaliContentService
|
|
|
$level = $this->paragraphLevel($book, $para);
|
|
|
// 缓存句子,段落外壳与标题级别有关,不进缓存
|
|
|
$key = self::paragraphCacheKey($book, $para, $channelUid, $format);
|
|
|
- $cached = Cache::tags([self::paragraphCacheTag($book, $para, $channelUid)])
|
|
|
- ->remember(
|
|
|
- $key,
|
|
|
- config('mint.cache.expire'),
|
|
|
- function () use ($book, $para, $channelUid, $format) {
|
|
|
- return $this->renderReadSentences($book, $para, $channelUid, $format);
|
|
|
- }
|
|
|
- );
|
|
|
+ $cached = Cache::remember(
|
|
|
+ $key,
|
|
|
+ config('mint.cache.expire'),
|
|
|
+ function () use ($book, $para, $channelUid, $format) {
|
|
|
+ return $this->renderReadSentences($book, $para, $channelUid, $format);
|
|
|
+ }
|
|
|
+ );
|
|
|
|
|
|
$result = [
|
|
|
'para' => $para,
|
|
|
@@ -700,19 +699,18 @@ class PaliContentService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 段落阅读模式缓存的 key
|
|
|
+ * 阅读模式支持的全部格式。forgetParagraph 需要逐格式清除缓存 key。
|
|
|
+ *
|
|
|
+ * @var array<int, string>
|
|
|
*/
|
|
|
- public static function paragraphCacheKey(int $book, int $para, string $channelUid, string $format): string
|
|
|
- {
|
|
|
- return "/read-para/{$book}-{$para}/{$channelUid}/{$format}";
|
|
|
- }
|
|
|
+ private const FORMATS = ['html', 'markdown', 'react', 'text'];
|
|
|
|
|
|
/**
|
|
|
- * 段落缓存的 tag。一个段落一个 channel 的全部格式共用一个 tag
|
|
|
+ * 段落阅读模式缓存的 key
|
|
|
*/
|
|
|
- public static function paragraphCacheTag(int $book, int $para, string $channelUid): string
|
|
|
+ public static function paragraphCacheKey(int $book, int $para, string $channelUid, string $format): string
|
|
|
{
|
|
|
- return "read-para:{$book}-{$para}:{$channelUid}";
|
|
|
+ return "/read-para/{$book}-{$para}/{$channelUid}/{$format}";
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -720,7 +718,9 @@ class PaliContentService
|
|
|
*/
|
|
|
public static function forgetParagraph(int $book, int $para, string $channelUid): void
|
|
|
{
|
|
|
- Cache::tags([self::paragraphCacheTag($book, $para, $channelUid)])->flush();
|
|
|
+ foreach (self::FORMATS as $format) {
|
|
|
+ Cache::forget(self::paragraphCacheKey($book, $para, $channelUid, $format));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|