|
|
|
@ -3,8 +3,7 @@ class Department < ApplicationRecord
|
|
|
|
|
|
|
|
|
|
has_many :department_members, dependent: :destroy
|
|
|
|
|
|
|
|
|
|
after_create_commit :reset_data_cache
|
|
|
|
|
after_update_commit :reset_data_cache
|
|
|
|
|
after_commit :reset_data_cache
|
|
|
|
|
|
|
|
|
|
def self.cached_names_data(school)
|
|
|
|
|
Rails.cache.fetch(names_data_cache_key(school.id), expires_in: 7.days) do
|
|
|
|
@ -16,9 +15,7 @@ class Department < ApplicationRecord
|
|
|
|
|
|
|
|
|
|
def reset_data_cache
|
|
|
|
|
# 清除部门名称缓存
|
|
|
|
|
if new_record? || name_previously_changed?
|
|
|
|
|
Rails.cache.delete(self.class.names_data_cache_key(school_id))
|
|
|
|
|
end
|
|
|
|
|
Rails.cache.delete(self.class.names_data_cache_key(school_id))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.names_data_cache_key(school_id)
|
|
|
|
|