I've got a web app and I'm trying to pre-cache my templates as suggested like this: https://golang.org/doc/articles/wiki/#tmp_10

Currently this is what I'm doing. (I've included example template helper functions to give you an idea) (a note that the App object is the rest of the app, handling the actual web serving and DB stuff)

///a function that the template can pass a different arg
func functiontakingarguments(arg1 string, arg2 string) (firststring string) {
    return arg1

}

func (app *App) defaultTemplHelpers(w http.ResponseWriter, r *http.Request) template.FuncMap {
    m := template.FuncMap{
        "sessionfoo": func() bool {
            //some function
            return hasUserSession(r)
        },
        "bar": functiontakingarguments,
    }
    /*
        Many many more template functions
    */
    return m
}

func myPageWithLayout(app *App, w http.ResponseWriter, r *http.Request, path string, file string, layout string, funcs template.FuncMap, data map[string]interface{}) {
    logger.Debugf("rendering template with layout %+v at path %+v, page %+v", layout, path, file)

    t, err := template.New(file).Funcs(funcs).ParseFiles(
        filepath.Join(templatesPath, path, file),
        filepath.Join(templatesPath, "layouts", layout),
    )

    if err != nil {
        logger.Errorf("error rendering html template %+v: %+v", file, err.Error())
        http.Error(w, "error", http.StatusInternalServerError)
        return
    }

    //previously used to establish default template data
    templData := map[string]interface{}{}
    // merge passed in data with our template data
    for k, v := range data {
        templData[k] = v
    }

    executeTemplate(w, t, templData)
}
///the following is an example of a template:

/*

apagewithfuncs.html:

<h1> Hello! </h1>
{{ functiontakingarguments "astring" "asecondstring" }}

{{ if sessionfoo }} Something to do with that session function {{else}} nevermind! {{end}}

*/

You can easily spot the first set of problems here, I bet. The templates have to be read from the disk every time for every request.

Because I have some template functions that rely on what user is viewing them, or session variables, I'm passing the r *http.Request into the template rendering function, so that when my helper functions are called, they have access to that request data.

As far as I can tell, that means I can't exactly pre-cache these templates as described in that earlier link (https://golang.org/doc/articles/wiki/#tmp_10)

So, first off, is this a bad way to do this in general? (Not to pass the buck, but some of this code came from another programmer)

Secondly, is there a way to make this more efficient? Like, caching some part of this but still able to use those helper functions? I'm pretty sure this whole setup is dragging my app performance way down, but I could be wrong. I've tried some ugly hacks like trying (someargs ...interface{}) and then type casting (yeah I'm a terrible sinner)