Removed unnecessary duplicate static caching

This commit is contained in:
andreimarcu 2015-10-14 14:58:27 -04:00
parent e1b2896c64
commit be15ba076d
1 changed files with 5 additions and 17 deletions

View File

@ -1,8 +1,6 @@
package main
import (
"bytes"
"io"
"net/http"
"net/url"
"os"
@ -40,8 +38,6 @@ func fileServeHandler(c web.C, w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, filePath)
}
var staticCache = make(map[string][]byte)
func staticHandler(c web.C, w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
if path[len(path)-1:] == "/" {
@ -53,23 +49,15 @@ func staticHandler(c web.C, w http.ResponseWriter, r *http.Request) {
}
filePath := strings.TrimPrefix(path, "/static/")
_, exists := staticCache[filePath]
if !exists {
file, err := staticBox.Open(filePath)
if err != nil {
notFoundHandler(c, w, r)
return
}
buf := bytes.NewBuffer(nil)
io.Copy(buf, file)
staticCache[filePath] = buf.Bytes()
}
w.Header().Set("Etag", timeStartedStr)
w.Header().Set("Cache-Control", "max-age=86400")
http.ServeContent(w, r, filePath, timeStarted, bytes.NewReader(staticCache[filePath]))
http.ServeContent(w, r, filePath, timeStarted, file)
return
}
}