From 7a9b5712c06d4a359a00b6f5ef9997da1fa11746 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Thu, 18 Jun 2015 10:54:28 +0800 Subject: [PATCH] =?UTF-8?q?message=E7=9A=84=E5=8A=A8=E6=80=81=E5=8D=95?= =?UTF-8?q?=E7=8B=AC=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/trustie/cache/clear_course_event.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/trustie/cache/clear_course_event.rb b/lib/trustie/cache/clear_course_event.rb index 98ec8b4fd..a5f44bf45 100644 --- a/lib/trustie/cache/clear_course_event.rb +++ b/lib/trustie/cache/clear_course_event.rb @@ -8,9 +8,23 @@ module Trustie after_create :clear_course_events } end + def clear_course_events - Rails.cache.delete("course_events_#{self.act.course_id}".to_sym) if Rails.env.production? && Setting.course_cahce_enabled? + if Rails.env.production? && Setting.course_cahce_enabled? + Rails.cache.delete(cache_key) + end + end + + def cache_key + course_id = nil + if Message === self.act + course_id = self.act.board.course_id + elsif self.act.respond_to?(:course_id) + course_id = self.act.course_id + end + "course_events_#{course_id}".to_sym end + end end end