From 140c71b4f8edaff9b84757110cc7ea724eef3954 Mon Sep 17 00:00:00 2001
From: Daniel Gerhardt <code@dgerhardt.net>
Date: Mon, 25 Jul 2016 16:09:06 +0200
Subject: [PATCH] Clear caches at fixed time intervals

---
 .../de/thm/arsnova/cache/CacheBuster.java     |  1 +
 .../arsnova/cache/ScheduledCacheBuster.java   | 52 +++++++++++++++++++
 2 files changed, 53 insertions(+)
 create mode 100644 src/main/java/de/thm/arsnova/cache/ScheduledCacheBuster.java

diff --git a/src/main/java/de/thm/arsnova/cache/CacheBuster.java b/src/main/java/de/thm/arsnova/cache/CacheBuster.java
index 9ea458b3..5291d6ee 100644
--- a/src/main/java/de/thm/arsnova/cache/CacheBuster.java
+++ b/src/main/java/de/thm/arsnova/cache/CacheBuster.java
@@ -19,6 +19,7 @@ package de.thm.arsnova.cache;
 
 import de.thm.arsnova.events.*;
 import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
 /**
diff --git a/src/main/java/de/thm/arsnova/cache/ScheduledCacheBuster.java b/src/main/java/de/thm/arsnova/cache/ScheduledCacheBuster.java
new file mode 100644
index 00000000..5c49dfc3
--- /dev/null
+++ b/src/main/java/de/thm/arsnova/cache/ScheduledCacheBuster.java
@@ -0,0 +1,52 @@
+package de.thm.arsnova.cache;
+
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+/** This component cleares caches at fixed time intervals:
+ * <ul>
+ *   <li><code>sessions</code>: 6h</li>
+ *   <li><code>skillquestions</code>, <code>lecturequestions</code>, <code>preparationquestions</code>,
+ *     <code>flashcardquestions</code>: 30min</li>
+ *   <li><code>questions</code>: 30min</li>
+ *   <li><code>answers</code>: 15min</li>
+ *   <li><code>learningprogress</code>: 15min</li>
+ * </ul>
+ */
+@Component
+public class ScheduledCacheBuster {
+
+	@CacheEvict(value = "sessions", allEntries = true)
+	@Scheduled(initialDelay = 1000 * 25, fixedRate = 1000 * 60 * 60 * 6)
+	private void clearSessionCache() { }
+
+	@CacheEvict(value = "questions", allEntries = true)
+	@Scheduled(initialDelay = 1000 * 50, fixedRate = 1000 * 60 * 30)
+	private void clearQuestionCache() { }
+
+	@CacheEvict(value = "skillquestions", allEntries = true)
+	@Scheduled(initialDelay = 1000 * 75, fixedRate = 1000 * 60 * 30)
+	private void clearSkillQuestionCache() { }
+
+	@CacheEvict(value = "lecturequestions", allEntries = true)
+	@Scheduled(initialDelay = 1000 * 100, fixedRate = 1000 * 60 * 30)
+	private void clearLectureQuestionCache() { }
+
+	@CacheEvict(value = "preparationquestions", allEntries = true)
+	@Scheduled(initialDelay = 1000 * 125, fixedRate = 1000 * 60 * 30)
+	private void clearPreparationQuestionCache() { }
+
+	@CacheEvict(value = "flashcardquestions", allEntries = true)
+	@Scheduled(initialDelay = 1000 * 150, fixedRate = 1000 * 60 * 30)
+	private void clearFlashcardQuestionCache() { }
+
+	@CacheEvict(value = "answers", allEntries = true)
+	@Scheduled(initialDelay = 1000 * 175, fixedRate = 1000 * 60 * 15)
+	private void clearAnswerCache() { }
+
+	@CacheEvict(value = "learningprogress", allEntries = true)
+	@Scheduled(initialDelay = 1000 * 200, fixedRate = 1000 * 60 * 15)
+	private void clearLearningProgressCache() { }
+
+}
-- 
GitLab