2015-06-18 09:13:20 +08:00
|
|
|
#coding=utf-8
|
|
|
|
|
|
|
|
module Trustie
|
|
|
|
module Cache
|
|
|
|
module ClearCourseEvent
|
|
|
|
def self.included(base)
|
|
|
|
base.class_eval{
|
|
|
|
after_create :clear_course_events
|
2015-06-19 14:49:18 +08:00
|
|
|
after_destroy :clear_course_events
|
2015-06-18 09:13:20 +08:00
|
|
|
}
|
|
|
|
end
|
2015-06-18 10:54:28 +08:00
|
|
|
|
2015-06-18 09:13:20 +08:00
|
|
|
def clear_course_events
|
2015-06-18 10:54:28 +08:00
|
|
|
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
|
2015-06-18 09:13:20 +08:00
|
|
|
end
|
2015-06-18 10:54:28 +08:00
|
|
|
|
2015-06-18 09:13:20 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|