Cache is used by default.

This commit is contained in:
Nathan Osman 2016-05-06 22:37:12 -07:00
parent af6ada6bd0
commit 02fe4d04b5
2 changed files with 8 additions and 3 deletions

4
cache/cache.go vendored
View File

@ -72,7 +72,9 @@ func (c *Cache) GetReader(rawurl string, maxAge time.Duration) (Reader, error) {
} }
e, _ := r.GetEntry() e, _ := r.GetEntry()
lastModified, _ := time.Parse(http.TimeFormat, e.LastModified) lastModified, _ := time.Parse(http.TimeFormat, e.LastModified)
if lastModified.Before(time.Now().Add(maxAge)) || e.Complete { if e.Complete &&
(maxAge == -1 ||
lastModified.Before(time.Now().Add(maxAge))) {
log.Println("[HIT]", rawurl) log.Println("[HIT]", rawurl)
return r, nil return r, nil
} }

View File

@ -36,10 +36,13 @@ func rewrite(rawurl string) string {
func maxAge(req *http.Request) time.Duration { func maxAge(req *http.Request) time.Duration {
d, err := cacheobject.ParseRequestCacheControl(req.Header.Get("Cache-Control")) d, err := cacheobject.ParseRequestCacheControl(req.Header.Get("Cache-Control"))
if err != nil { if err == nil || d.NoCache {
return 0
}
if d.MaxAge > 0 {
return time.Duration(d.MaxAge) return time.Duration(d.MaxAge)
} }
return 0 return -1
} }
func (s *Server) writeHeaders(w http.ResponseWriter, e *cache.Entry) { func (s *Server) writeHeaders(w http.ResponseWriter, e *cache.Entry) {