diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2005-07-05 02:46:49 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2005-07-05 02:46:49 +0000 |
commit | 9933ec82b2267bfd2f1fa4dd747ea4c5520870f5 (patch) | |
tree | 72ea70feac7ecc26481b9a54add6a4cae8f0dd39 /actionpack/lib | |
parent | d80d9a52bdc8b6ddf3b1ec846ddafd96d4ab3e8c (diff) | |
download | rails-9933ec82b2267bfd2f1fa4dd747ea4c5520870f5.tar.gz rails-9933ec82b2267bfd2f1fa4dd747ea4c5520870f5.tar.bz2 rails-9933ec82b2267bfd2f1fa4dd747ea4c5520870f5.zip |
r2840@asus: jeremy | 2005-07-05 00:42:27 -0700
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
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/routing.rb | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb index 3771d3fead..6a0988b754 100644 --- a/actionpack/lib/action_controller/routing.rb +++ b/actionpack/lib/action_controller/routing.rb @@ -416,21 +416,33 @@ module ActionController 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}" |