Переглянути джерело

refactor(wuliu):优化物流查询次数缓存键生成逻辑

runphp 5 місяців тому
батько
коміт
e4239422d0
1 змінених файлів з 3 додано та 2 видалено
  1. 3 2
      src/Entity/ExtensionWuLiuEntity.php

+ 3 - 2
src/Entity/ExtensionWuLiuEntity.php

@@ -22,8 +22,9 @@ class ExtensionWuLiuEntity extends BaseEntity
             return $entity->toArray();
         }
         // 一个人一天最多查询100次
-        $times = Cache::remember('wuliu_'.date('Ymd').'_' . $userID, function () {
-            return Cache::get('wuliu_'.date('Ymd').'_' . $userID, 0) + 1;
+        $cacheKey = 'wuliu_' . date('Ymd') . '_' . $userID;
+        $times = Cache::remember($cacheKey, function () use ($cacheKey) {
+            return Cache::get($cacheKey, 0) + 1;
         }, 86400);
         if ($times > 100) {
             throw_logic_exception('查询太过频繁,请明天再试');