Cache is used by default.
This commit is contained in:
parent
af6ada6bd0
commit
02fe4d04b5
4
cache/cache.go
vendored
4
cache/cache.go
vendored
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user