Add memoization to lazy param parsing

This commit is contained in:
Fatih Kadir Akın 2016-03-06 22:39:10 +02:00
parent 4ee4b66135
commit 043d1c8aa2
2 changed files with 5 additions and 3 deletions

View file

@ -2,7 +2,6 @@
# information such as params, content_type e.g
class HTTP::Server
class Context
def params
@request.url_params = route_lookup.params
@params ||= Kemal::ParamParser.new(@request)

View file

@ -18,7 +18,12 @@ class Kemal::ParamParser
{% for method in %w(url query body json) %}
def {{method.id}}
# check memoization
return @{{method.id}} if @{{method.id}}_parsed
parse_{{method.id}}
# memoize
@{{method.id}}_parsed = true
@{{method.id}}
end
{% end %}
@ -67,6 +72,4 @@ class Kemal::ParamParser
end
part_params
end
end