Navigation Menu

Skip to content

Commit

Permalink
r2840@asus: jeremy | 2005-07-05 00:42:27 -0700
Browse files Browse the repository at this point in the history
 Ticket 1233 - Cache recognized routes
 r2842@asus:  jeremy | 2005-07-05 00:53:16 -0700
 update changelog
 r2843@asus:  jeremy | 2005-07-05 00:54:11 -0700
 cache recognized routes.  clear cache with clear_recognized_routes_cache\!


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1694 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Jul 5, 2005
1 parent d80d9a5 commit 9933ec8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*

* Cache recognized routes. #1233 [skaes@web.de]

* Cache several controller variables that are expensive to calculate. #1229 [skaes@web.de]

* The session class backing CGI::Session::ActiveRecordStore may be replaced with any class that duck-types with a subset of Active Record. See docs for details. #1238 [skaes@web.de]
Expand Down
36 changes: 24 additions & 12 deletions actionpack/lib/action_controller/routing.rb
Expand Up @@ -416,21 +416,33 @@ def write_generation
return (method_sources << code)
end

@@recognized_route_cache = {}
def recognize(request)
string_path = request.path
string_path.chomp! if string_path[0] == ?/
path = string_path.split '/'
path.shift

hash = recognize_path(path)
recognition_failed(request) unless hash && hash['controller']

controller = hash['controller']
hash['controller'] = controller.controller_path
request.path_parameters = hash
controller.new
if recognized = @@recognized_route_cache[request.path]
controller, options = recognized
request.path_parameters = options
controller
else
string_path = request.path
string_path.chomp! if string_path[0] == ?/
path = string_path.split '/'
path.shift

hash = recognize_path(path)
recognition_failed(request) unless hash && hash['controller']

controller = hash['controller']
hash['controller'] = controller.controller_path
request.path_parameters = hash
@@recognized_route_cache[request.path] = [controller, hash]
controller.new
end
end
alias :recognize! :recognize

def clear_recognized_route_cache!
@@recognized_route_cache.clear
end

def recognition_failed(request)
raise ActionController::RoutingError, "Recognition failed for #{request.path.inspect}"
Expand Down

0 comments on commit 9933ec8

Please sign in to comment.