MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / cacheControlMaxAge

Function cacheControlMaxAge

auth/oidc.go:727–751  ·  view source on GitHub ↗

Returns the value of max-age directive from the Cache-Control HTTP header, i.e. the maximum amount of time in seconds that the fetched responses are allowed to be used again (from the time when a request is made). The second value (ok) is true if max-age exists, and false if not.

(header http.Header)

Source from the content-addressed store, hash-verified

725// amount of time in seconds that the fetched responses are allowed to be used again (from the
726// time when a request is made). The second value (ok) is true if max-age exists, and false if not.
727func cacheControlMaxAge(header http.Header) (maxAge time.Duration, ok bool, err error) {
728 for _, field := range strings.Split(header.Get("Cache-Control"), ",") {
729 parts := strings.SplitN(strings.TrimSpace(field), "=", 2)
730 k := strings.ToLower(strings.TrimSpace(parts[0]))
731 if k != "max-age" {
732 continue
733 }
734 if len(parts) == 1 {
735 return 0, false, errors.New("max-age has no value")
736 }
737 v := strings.TrimSpace(parts[1])
738 if v == "" {
739 return 0, false, errors.New("max-age has empty value")
740 }
741 age, err := strconv.Atoi(v)
742 if err != nil {
743 return 0, false, err
744 }
745 if age <= 0 {
746 return 0, false, nil
747 }
748 return time.Duration(age) * time.Second, true, nil
749 }
750 return 0, false, nil
751}
752
753// getExpiration calculates the freshness lifetime by computing the number of seconds difference
754// between the Expires value and the Date value on the response header. The second value (ok) is

Callers 3

cacheableFunction · 0.85

Calls 1

GetMethod · 0.45

Tested by 2