فهرست منبع

feat: 题目信息和用例缓存

haha 3 سال پیش
والد
کامیت
992aaf0852

+ 10 - 0
seec-oj-server/pom.xml

@@ -84,6 +84,16 @@
             <version>1.4.2.Final</version>
         </dependency>
 
+        <!-- caching -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-cache</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>net.sf.ehcache</groupId>
+            <artifactId>ehcache</artifactId>
+        </dependency>
+
     </dependencies>
 
     <build>

+ 2 - 0
seec-oj-server/src/main/java/cn/seecoder/ojserver/OjServerApplication.java

@@ -2,8 +2,10 @@ package cn.seecoder.ojserver;
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cache.annotation.EnableCaching;
 
 @SpringBootApplication
+@EnableCaching
 public class OjServerApplication {
     public static void main(String[] args) {
         SpringApplication.run(OjServerApplication.class, args);

+ 19 - 0
seec-oj-server/src/main/java/cn/seecoder/ojserver/config/CacheConfig.java

@@ -0,0 +1,19 @@
+package cn.seecoder.ojserver.config;
+
+import net.sf.ehcache.CacheManager;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.cache.ehcache.EhCacheCacheManager;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+//@Configuration
+//@EnableCaching
+//@ConditionalOnProperty(prefix = "caching", name = "enabled", havingValue = "true")
+public class CacheConfig {
+    //EhCacheManager
+//    @Bean
+//    public EhCacheCacheManager cacheManager(CacheManager cm) {
+//        return new EhCacheCacheManager(cm);
+//    }
+}

+ 6 - 0
seec-oj-server/src/main/java/cn/seecoder/ojserver/manager/QuestionManager.java

@@ -7,6 +7,7 @@ import cn.seecoder.ojserver.dao.TestCaseDAO;
 import cn.seecoder.ojserver.exception.ThirdPartyServiceException;
 import cn.seecoder.ojserver.model.vo.CompleteQuestionVO;
 import cn.seecoder.ojserver.utils.thirdparty.QuestionThirdPartyService;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
@@ -25,11 +26,16 @@ public class QuestionManager {
         this.testCaseDAO = testCaseDAO;
     }
 
+
+    @Cacheable(value = "problem")
     public Optional<Problem> getProblemById(Integer id){
+        System.out.println("getProblemById:"+id);
         return problemDAO.findById(id);
     }
 
+    @Cacheable(value = "testCaseByProblemId")
     public List<TestCase> getTestCaseByProblemId(Integer problemId){
+        System.out.println("getTestCaseByProblemId:"+problemId);
         return testCaseDAO.findByProblem_Id(problemId);
     }
 }