Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
caching_headers.h
Go to the documentation of this file.
1 // Copyright 2011 Google Inc. All Rights Reserved.
18 
19 #ifndef PAGESPEED_KERNEL_HTTP_CACHING_HEADERS_H_
20 #define PAGESPEED_KERNEL_HTTP_CACHING_HEADERS_H_
21 
22 #include "base/logging.h"
26 
27 namespace net_instaweb {
32 
41  public:
43  explicit CachingHeaders(int status_code);
44  virtual ~CachingHeaders();
45 
47  virtual bool Lookup(const StringPiece& key, StringPieceVector* values) = 0;
48 
50  void set_url(StringPiece x) { url_ = x; }
51 
58  bool IsCacheable();
59 
61  bool IsProxyCacheable();
62 
64  bool IsExplicitlyCacheable();
65 
70  bool GetFreshnessLifetimeMillis(int64* out_freshness_lifetime_millis);
71 
75 
80 
82  bool MustRevalidate();
83 
85  bool ProxyRevalidate();
86 
92 
94  virtual bool IsLikelyStaticResourceType() const = 0;
95 
98  virtual bool IsCacheableResourceStatusCode() const = 0;
99 
100  bool IsRedirectStatusCode() const;
101 
102  int status_code() const { return status_code_; }
103 
107 
108  private:
109  void ParseCacheControlIfNecessary();
110 
113  bool IsHeuristicallyCacheable();
114 
117  bool ComputeIsCacheable();
118  bool ComputeIsProxyCacheable();
119  bool ComputeIsHeuristicallyCacheable();
120  bool ComputeFreshnessLifetimeMillis(int64* out_freshness_lifetime_millis);
121  bool ComputeHasExplicitNoCacheDirective();
122 
124  template<class T> class Optional {
125  public:
126  Optional() : has_value_(false) {}
127  ~Optional() {}
128 
129  bool has_value() const { return has_value_; }
130 
131  T value() const {
133  DCHECK(has_value());
134  return value_;
135  }
136 
137  void set_value(T value) {
138  value_ = value;
139  has_value_ = true;
140  }
141 
142  private:
143  T value_;
144  bool has_value_;
145 
146 
147  };
148 
149  int status_code_;
150  StringPiece url_;
151  bool parsed_cache_control_;
152 
156  bool public_;
157  bool private_;
158  bool no_transform_;
159  bool must_revalidate_;
160  bool proxy_revalidate_;
161  bool no_cache_;
162  bool no_store_;
163  bool cache_control_parse_error_;
164  bool expires_invalid_;
165  Optional<int> max_age_seconds_;
166  Optional<int64> expires_ms_;
167 
170  Optional<int64> freshness_lifetime_millis_;
171  Optional<bool> is_cacheable_;
172  Optional<bool> is_proxy_cacheable_;
173  Optional<bool> is_explicitly_cacheable_;
174  Optional<bool> is_heuristically_cacheable_;
175  Optional<bool> has_explicit_no_cache_directive_;
176 
177 
178 };
179 
180 }
181 
182 #endif
bool IsExplicitlyCacheable()
Is this resource explicitly marked cacheable?
Definition: caching_headers.h:40
bool IsProxyCacheable()
Is the resource likely to be cached by proxies?
bool ProxyRevalidate()
Determines whether the caching headers have a proxy-revalidate directive.
CachingHeaders(int status_code)
All StringPieces must outlive the CachingHeaders class.
void set_url(StringPiece x)
To obtain correct heuristics on URLs with query-parameters, supply the URL.
Definition: caching_headers.h:50
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
bool GetFreshnessLifetimeMillis(int64 *out_freshness_lifetime_millis)
virtual bool IsLikelyStaticResourceType() const =0
Is the given resource type usually associated wiht static resources?
bool MustRevalidate()
Determines whether the caching headers have a must-revalidate directive.
GoogleString GenerateDisabledCacheControl()
virtual bool IsCacheableResourceStatusCode() const =0
virtual bool Lookup(const StringPiece &key, StringPieceVector *values)=0
Implementors supply this method to provide HTTP response header values.