配置缓存是否启用

Signed-off-by: alan <547533434@qq.com>
This commit is contained in:
alan 2015-06-29 16:12:00 +08:00
parent b47f9a6e9f
commit 0d42ddef09
13 changed files with 45 additions and 22 deletions

View File

@ -1871,6 +1871,24 @@ module ApplicationHelper
end
# cache_if 判断是否启用cache rails3+没有这个
def cache_if (condition, name = {}, cache_options = {}, &block)
if condition
cache(name, cache_options, &block)
else
yield
end
end
# cache_unless 判断是否启用cache rails3+没有这个
def cache_unless (condition, name = {}, cache_options = {}, &block)
if !condition
cache(name, cache_options, &block)
else
yield
end
end
private
def wiki_helper

View File

@ -21,7 +21,7 @@ class JournalsForMessage < ActiveRecord::Base
after_destroy :delete_kindeditor_assets
belongs_to :project,
:foreign_key => 'jour_id',
:conditions => "#{self.table_name}.jour_type = 'Project' "
:conditions => "#{self.table_name}.jour_type = 'Project' ", :touch => true
belongs_to :course,
:foreign_key => 'jour_id', :touch => true

View File

@ -21,7 +21,7 @@ class News < ActiveRecord::Base
include ApplicationHelper
has_many_kindeditor_assets :assets, :dependent => :destroy
#added by nwb
belongs_to :course
belongs_to :course, :touch => true
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
has_many :comments, :as => :commented, :dependent => :delete_all, :order => "created_on"
# fq

View File

@ -12,7 +12,7 @@
div.recall_con .reply_btn{margin-left:525px;margin-top:5px;}
</style>
<%= javascript_include_tag "/assets/kindeditor/kindeditor" %>
<% cache [:courses_jours, @course, User.current.logged? ] do%>
<% cache_if Setting.redis_cache_enabled? , [:courses_jours, @course, User.current.logged? ] do%>
<div class="msg_box" id='leave-message' nhname="new_message">
<%# reply_allow = JournalsForMessage.create_by_user? User.current %>
<h4><%= l(:label_leave_message) %></h4>
@ -42,7 +42,7 @@
<% end %>
<div class="cl"></div>
<% if @page == "1" %>
<% cache [:courses_jours_list, @course, @jour.maximum(:updated_on), User.current.logged? ] do %>
<% cache_if Setting.redis_cache_enabled? , [:courses_jours_list, @course, @jour.maximum(:updated_on), User.current.logged? ] do %>
<div id="history">
<%= render :partial => 'history',:locals => { :contest => @contest, :journals => @jour, :page => @page, :state => false} %>
</div>

View File

@ -65,7 +65,7 @@
<div class="resource"><!--资源库内容开始--->
<div class="re_top">
<% cache [:course_file_search, @course] do %>
<% cache_if Setting.redis_cache_enabled? , [:course_file_search, @course] do %>
<%= form_tag( search_course_files_path(@course), method: 'get',:class => "re_search f_l",:remote=>true) do %>
<%= text_field_tag 'name', params[:name], name: "name", :class => 're_schbox',:style=>"padding: 0px"%>
<%= submit_tag "课内搜索", :class => "re_schbtn b_lblue",:name => "incourse",:id => "incourse", :onmouseover => "presscss('incourse')",:onmouseout =>"buttoncss()" %>
@ -85,7 +85,7 @@
<% end %>
</div><!---re_top end-->
<div class="cl"></div>
<% cache [:course_file_list, @obj_attachments.max().updated_at] do %>
<% cache_if Setting.redis_cache_enabled? , [:course_file_list, @obj_attachments.max().updated_at] do %>
<div class="re_con" id="course_list">
<%= render :partial => 'course_list',:locals => {course: @course,all_attachments: @all_attachments,sort:@sort,order:@order,curse_attachments:@obj_attachments} %>
</div><!---re_con end-->

View File

@ -29,7 +29,7 @@
<%= render :partial => 'layouts/new_header' %>
<div class="cl"></div>
<!-- add by alan 对课程当前位置以及搜索框做缓存 -->
<% cache [:course_head,@course.id] do%>
<% cache_if Setting.redis_cache_enabled? , [:course_head,@course.id] do%>
<div id="TopBar">
<div class="topbar_info02 fl">
@ -68,7 +68,7 @@
<div id="LSide" class="fl">
<div class="project_info">
<!-- 对课程的图片及id 片段做缓存 -->
<% cache [:course_pic, @course.id] do%>
<% cache_if Setting.redis_cache_enabled? , [:course_pic, @course.id] do%>
<div class="pr_info_logo fl mr10 mb5">
<!--<a href="#"><img src="images/courses/pic_courses.jpg" width="60" height="60" alt="logo" /></a>-->
<%= image_tag(url_to_avatar(@course), :width => "60", :height => "60") %>
@ -108,7 +108,7 @@
<%= l(:project_module_attachments)%><%= link_to course_file_num, course_files_path(@course), :class => 'info_foot_num c_blue',:id=>'courses_files_count_info' %></div>
<div class="cl"></div>
</div><!--课程信息 end-->
<% cache [:course_info_left, @course.id ] do%>
<% cache_if Setting.redis_cache_enabled? , [:course_info_left, @course ] do%>
<div class="info_box">
<ul>
<li><%= l(:label_main_teacher)%> :&nbsp;&nbsp;<%= link_to(@course.teacher.lastname+@course.teacher.firstname, user_path(@course.teacher), :class => 'c_dblue') %></li>
@ -160,7 +160,7 @@
</div><!--项目侧导航 end-->
<div class="cl"></div>
<% cache [:course_description, expire_in: 2.hours] do%>
<% cache_if Setting.redis_cache_enabled? , [:course_description, expire_in: 2.hours] do%>
<div class="project_intro">
<div id="course_description" class="course_description">
<h4 ><%= l(:label_course_brief_introduction)%></h4>
@ -195,12 +195,12 @@
</div><!--Content end-->
<div class="cl"></div>
<% cache 'footer', expire_in: 2.hours do%>
<% cache_if Setting.redis_cache_enabled? , 'footer', expire_in: 2.hours do%>
<%= render :partial => 'layouts/new_footer' %>
<% end %>
<div class="cl"></div>
</div><!--Container end-->
<% cache 'feedback', expire_in: 2.hours do%>
<% cache_if Setting.redis_cache_enabled? , 'feedback', expire_in: 2.hours do%>
<%= render :partial => 'layouts/new_feedback' %>
<% end %>
<div id="ajax-indicator" style="display:none;">

View File

@ -27,9 +27,9 @@
</p>
<% else %>
<% cache [:course_news_list, @course, @newss.first().updated_on, @newss.count] do%>
<% cache_if Setting.redis_cache_enabled? , [:course_news_list, @course, @newss.first().updated_on] do%>
<% @newss.each do |news| %>
<% cache [:course_news_each, news.id, news.updated_on] do%>
<% cache_if Setting.redis_cache_enabled? , [:course_news_each, news.id, news.updated_on] do%>
<div class="problem_main upload_img">
<%= link_to image_tag(url_to_avatar(news.author),:width => 42,:height => 42), user_path(news.author), :class => "problem_pic fl" %>
<div class="problem_txt fl mt5">

View File

@ -27,7 +27,7 @@
<p style="padding-left: 180px;"><%= setting_select :text_formatting, Redmine::WikiFormatting.format_names.collect{|name| [name, name.to_s]}, :blank => :label_none %></p>
<p style="padding-left: 180px;"><%= setting_check_box :cache_formatted_text %></p>
<p style="padding-left: 180px;"><%= setting_check_box :redis_cache_enabled %></p>
<p style="padding-left: 180px;"><%= setting_select :wiki_compression, [['Gzip', 'gzip']], :blank => :label_none %></p>
<p style="padding-left: 180px;"><%= setting_text_field :feeds_limit, :size => 6 %></p>

View File

@ -5,7 +5,7 @@
<!-- 用来显示三大对象的主页中的tag 故是全部显示 -->
<% if @tags.size > 0 %>
<% cache [:course_tags, @tags.size] do%>
<% cache_if Setting.redis_cache_enabled? , [:course_tags, @tags.size] do%>
<% @tags.each do |tag| %>
<span class="re_tag f_l " id="tag">
<%= link_to tag, :controller => "tags", :action => "index", :q => tag, :object_flag => object_flag, :obj_id => obj.id, :class => 'pt5' %>

View File

@ -175,7 +175,7 @@
<%break if Time.new.strftime("%Y").to_i - year_now >= 2%>
<% all_new_hot_course += find_all_new_hot_course(9-(all_new_hot_course.count + cur_school_course.count), @school_id, year_now, course_term)%>
<% end%>
<% cache [:course_list, all_new_hot_course.max().updated_at] do %>
<% cache_if Setting.redis_cache_enabled? , [:course_list, all_new_hot_course.max().updated_at] do %>
<%= render :partial => 'course_list', :locals => {:course_list => all_new_hot_course} %>
<% end %>
<% end %>
@ -187,7 +187,7 @@
<div id="J_Slide" class="d-p-index-box d-p-index-hot" style="float: right;">
<% topics = find_new_forum_topics(10) %>
<% cache [:course_topics, topics.maximum(:updated_at)] do%>
<% cache_if Setting.redis_cache_enabled? , [:course_topics, topics.maximum(:updated_at)] do%>
<h3 style="padding-bottom:0px ;margin-left: 5px; color: #e8770d;">
<strong><%= l(:label_issue_feedback_activities)%></strong>
<%= link_to l(:label_my_question), newbie_send_path, {:class => 'orangeButton idea_btn', :style => "color: #EEEEEE"} %>
@ -221,7 +221,7 @@
</span>
<span class="memo_last_person" title="<%= topic.last_reply.author.login unless (topic.last_reply.nil? || topic.last_reply.author.nil?)%>">
<% unless (topic.last_reply.nil? || topic.last_reply.author.nil?) %>
<% cache [:topic,topic, topic.last_reply.updated_at] do%>
<% cache_if Setting.redis_cache_enabled? , [:topic,topic, topic.last_reply.updated_at] do%>
<%= l(:label_final_reply)%>
<%=link_to topic.last_reply.author.login.truncate(10, omission: '...'),user_path(topic.last_reply.author),title: topic.last_reply.author.login%>
<% end %>

View File

@ -81,7 +81,7 @@
<%= link_to l(:label_join_project), join_project_projects_path ,:remote => true, :class => 'icon icon-add' %>
&nbsp;&nbsp;&nbsp;&nbsp;
<% end %> </span>
<% cache :project_list, :expire_in => 2.hours do%>
<% cache_if Setting.redis_cache_enabled? , :project_list, :expire_in => 2.hours do%>
<div class="d-p-projectlist-box">
<ul class="d-p-projectlist">
@ -127,7 +127,7 @@
</div>
<div class="welcome-box-list-new memo_activity">
<% topics = find_new_forum_topics(12) %>
<% cache [:topics, topics.maximum(:updated_at)] do%>
<% cache_if Setting.redis_cache_enabled? , [:topics, topics.maximum(:updated_at)] do%>
<% topics.includes(:forum, :last_reply, :author).each do |topic|%>
<li class="message-brief-intro" style="line-height:1.4em;">
@ -147,7 +147,7 @@
</span>
<span class="memo_last_person">
<% unless (topic.last_reply.nil? || topic.last_reply.author.nil?) %>
<% cache [:topic,topic, topic.last_reply.updated_at] do%>
<% cache_if Setting.redis_cache_enabled? , [:topic,topic, topic.last_reply.updated_at] do%>
<%= l(:label_final_reply)%>
<%=link_to topic.last_reply.author.login.truncate(10, omission: '...'),user_path(topic.last_reply.author),title: topic.last_reply.author.login%>
<% end %>

View File

@ -237,6 +237,7 @@ zh:
setting_start_of_week: 日历开始于
setting_rest_api_enabled: 启用REST web service
setting_cache_formatted_text: 缓存格式化文字
setting_redis_cache_enabled: 是否启用缓存
setting_default_notification_option: 默认提醒选项
setting_commit_logtime_enabled: 激活时间日志
setting_commit_logtime_activity_id: 记录的活动

View File

@ -68,6 +68,10 @@ delayjob_enabled:
default: 1
course_cahce_enabled:
default: 1
### redis cache
redis_cache_enabled:
default: 1
bcc_recipients:
default: 1
plain_text_mail: