소스 검색

药品搜索添加缓存

cc12458 11 달 전
부모
커밋
8e47e545ca
1개의 변경된 파일6개의 추가작업 그리고 1개의 파일을 삭제
  1. 6 1
      src/api/select-page.js

+ 6 - 1
src/api/select-page.js

@@ -1,8 +1,13 @@
 import {drugsSearchForMechanism, drugsSearchForSystem} from "@/api/drugs/drugs";
 
+let drugsSearchForSystemCache = new Map();
+
 export default {
   'drugsSearchForSystem': (query) => {
-    return drugsSearchForSystem({name: query.name || ''})
+    const name = query.name || '';
+    if (drugsSearchForSystemCache.size > 100) drugsSearchForSystemCache.clear();
+    if (!drugsSearchForSystemCache.has(name)) drugsSearchForSystemCache.set(name, drugsSearchForSystem({name}));
+    return drugsSearchForSystemCache.get(name);
   },
   'drugsSearchForMechanism': (query) => {
     return drugsSearchForMechanism({