diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 289d72d..2c7ed51 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,7 +4,10 @@ class ApplicationController < ActionController::Base helper :all # include all helpers, all the time + caches_page :show, :graphml, :index + around_filter :neo_tx + after_filter :invalidate_cache, :only => [:create, :update, :link, :unlink] # See ActionController::RequestForgeryProtection for details # Uncomment the :secret if you're not using the cookie session store @@ -127,4 +130,14 @@ def neo_tx yield Neo4j::Transaction.finish end + + def invalidate_cache + cache_dir = ActionController::Base.page_cache_directory + RAILS_DEFAULT_LOGGER.info "INVALIDATE CACHE #{cache_dir}" + unless cache_dir == RAILS_ROOT+"/public" + RAILS_DEFAULT_LOGGER.info "remove cache dir '#{cache_dir}'" + FileUtils.rm_r(Dir.glob(cache_dir+"/*")) rescue Errno::ENOENT + RAILS_DEFAULT_LOGGER.info("Cache directory '#{cache_dir}' fully swept.") + end + end end diff --git a/config/environment.rb b/config/environment.rb index 6997199..168aef3 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -7,6 +7,8 @@ require File.join(File.dirname(__FILE__), 'boot') Rails::Initializer.run do |config| + config.action_controller.page_cache_directory = RAILS_ROOT+"/public/cache/" + # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded.