|
- class HomeworkCommonCache
- class<<self
-
- #-----------------------------作业
- def homework_common_cache(id)
- key = "homework_common:"+id.to_s
- data = Rails.cache.read(key) rescue nil
- if data.nil?
- #直接存数据库对象
- data = HomeworkCommon.find(id) rescue nil
- if data
- Rails.cache.write(key,data,{ expires_in: 90.minutes }) rescue Rails.cache.delete(key)
- end
- end
- data
- end
-
- #更新
- def update_homework_common_cache(id,homework_common)
- key = "homework_common:"+id.to_s
- data = Rails.cache.read(key)
- if data.nil?
- else
- Rails.cache.write(key,homework_common,{ expires_in: 90.minutes }) rescue Rails.cache.delete(key)
- end
- end
-
- #删除
- def delete_homework_common_cache(id)
- key = "homework_common:"+id.to_s
- Rails.cache.delete(key)
- end
-
- end
- end
|