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 72a0e368..67a531f1 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 @@ -112,6 +112,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 9eb824ae..290b1092 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 @@ -226,8 +226,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)