From a5e65a2ff26e185b0ffcf052f0ddd58e06fe51ee Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 24 Nov 2020 15:01:26 +0100 Subject: [PATCH] fixed exams for exam list must be up to date (evict cache) --- .../session/impl/ExamSessionCacheService.java | 12 ++++++++++++ .../session/impl/ExamSessionServiceImpl.java | 2 ++ 2 files changed, 14 insertions(+) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionCacheService.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionCacheService.java index bb2ab02c..a6fabcc9 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionCacheService.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionCacheService.java @@ -110,6 +110,18 @@ public class ExamSessionCacheService { return exam; } + @CacheEvict( + cacheNames = CACHE_NAME_RUNNING_EXAM, + key = "#examId") + public Long evict(final Long examId) { + + if (log.isDebugEnabled()) { + log.debug("Conditional eviction of running Exam from cache: {}", examId); + } + + return examId; + } + public boolean isRunning(final Exam exam) { if (exam == null) { return false; diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionServiceImpl.java index afebcd43..3a60a0dd 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionServiceImpl.java @@ -222,8 +222,10 @@ public class ExamSessionServiceImpl implements ExamSessionService { @Override public Result> getRunningExamsForInstitution(final Long institutionId) { + // NOTE: we evict the exam from the cache (if present) to ensure user is seeing always the current state of the Exam return this.examDAO.allIdsOfInstitution(institutionId) .map(col -> col.stream() + .map(this.examSessionCacheService::evict) .map(this::getRunningExam) .filter(Result::hasValue) .map(Result::get)