Commit 00597432 authored by Dustin L. Howett's avatar Dustin L. Howett
Browse files

Cache var lookups against dp in vctx.

parent 0e161b7d
......@@ -22,6 +22,15 @@ func varFromDataProvider(dp DataProvider) func(vctx viewContext, name string) in
// otherwise, capture dp and use it for view value generation.
return func(vctx viewContext, name string) interface{} {
return dp.ViewValue(vctx.r, name)
if vctx.varCache != nil {
if val, ok := vctx.varCache[name]; ok {
return val
}
} else {
vctx.varCache = make(map[string]interface{})
}
val := dp.ViewValue(vctx.Request, name)
vctx.varCache[name] = val
return val
}
}
......@@ -13,11 +13,17 @@ import (
type viewContext struct {
page string
r *http.Request
// unguarded vis-a-vis concurrency: a single viewContext is not used in
// a multithreaded context.
varCache map[string]interface{}
}
// viewID is the internal interface that allows us to differentiate page-based IDs from string-based IDs
// viewID is the internal interface that allows us to differentiate page-based
// IDs from string-based IDs
type viewID interface {
// template returns the name of the template used to render the view with this ID
// template returns the name of the template used to render the view
// with this ID
template() string
// baseContext creates a new viewContext with pre-seeded values.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment