Problem with cache expiration in projects module on redmine
Added by Md Shahadat Hossain over 11 years ago
Hi community,
Currently i am using redmine_projects_accordion plugin for presentation of projects and sub projects in my redmine application.Also i deployed caching in my redmine application for faster page response and i am using action and page caching.While expiring the existing cache on update, create or delete action i am using sweeper class for project module.But when i create a new sub-project under root project the cache expires properly and project list is also updated.But when i am entering in my root project ,i can't see my newly created sub-project listing under the root project overview.But it was working before caching mechanism deployed. So i would be happy if someone can give any solution or advise regarding this issue. I also attached some screenshot for better understanding of the issue.
CODE FOR CACHE EXPIRE IN SWEEPER CLASS:
class ProjectsSweeper < ActionController::Caching::Sweeper
observe Project,Issue
def after_create(project)
expire_cache_for_page(project)
expire_cache_for_action(project)
end
def after_update(project)
#project = Project.find params[:project_id]
expire_cache_for_page(project)
expire_cache_for_action(project)
end
def after_destroy(project)
#project = Project.find params[:id]
expire_cache_for_page(project)
expire_cache_for_action(project)
end
def after_save(project)
expire_cache_for_page(project)
expire_cache_for_action(project)
end
private
def expire_cache_for_page(project)
expire_page(:controller => 'projects', :action => 'index')
expire_page(:controller => 'projects',:action => 'show',:id => project)
cache_dir = ActionController::Base.page_cache_directory
FileUtils.rm_r(Dir.glob(cache_dir + "/projects/*")) rescue Errno::ENOENT
end
def expire_cache_for_action(project)
expire_action(:controller => 'projects', :action => 'index')
expire_action(:controller => 'projects',:action => 'show',:id => project)
end
end