|
@@ -3,6 +3,7 @@ package com.jtxt.demo.service;
|
|
|
import com.jtxt.demo.model.Question;
|
|
|
import com.jtxt.demo.model.QuestionCategory;
|
|
|
import com.jtxt.demo.repository.QuestionRepository;
|
|
|
+import com.jtxt.demo.util.CacheStore;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -11,6 +12,8 @@ import java.util.List;
|
|
|
public class QuestionServiceImpl implements QuestionService {
|
|
|
@Autowired
|
|
|
QuestionRepository questionRepository;
|
|
|
+ @Autowired
|
|
|
+ private CacheStore<Question> questionCache;
|
|
|
@Override
|
|
|
public Question createQuestion(Question question) {
|
|
|
return questionRepository.insert(question);
|
|
@@ -51,7 +54,12 @@ public class QuestionServiceImpl implements QuestionService {
|
|
|
|
|
|
@Override
|
|
|
public Question findQuestionById(String id) {
|
|
|
- return questionRepository.findById(id).orElse(null);
|
|
|
+ Question question = questionCache.get(id);
|
|
|
+ if (question == null) {
|
|
|
+ question = questionRepository.findById(id).orElse(null);
|
|
|
+ if (question != null) questionCache.add(id, question);
|
|
|
+ }
|
|
|
+ return question;
|
|
|
}
|
|
|
|
|
|
@Override
|