Skip to content

Commit

Permalink
Added rails caches_page to increase performance
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas authored and sashaagafonoff committed Oct 29, 2009
1 parent e0c3df7 commit 781fbd7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/controllers/application_controller.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions config/environment.rb
Expand Up @@ -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.
Expand Down

0 comments on commit 781fbd7

Please sign in to comment.