c->buf->last += n;
c->valid_sec = h->valid_sec;
+ c->updating_sec = h->updating_sec;
+ c->error_sec = h->error_sec;
c->last_modified = h->last_modified;
c->date = h->date;
c->valid_msec = h->valid_msec;
now = ngx_time();
if (c->valid_sec < now) {
+ c->stale_updating = c->valid_sec + c->updating_sec >= now;
+ c->stale_error = c->valid_sec + c->error_sec >= now;
ngx_shmtx_lock(&cache->shpool->mutex);
h->version = NGX_HTTP_CACHE_VERSION;
h->valid_sec = c->valid_sec;
+ h->updating_sec = c->updating_sec;
+ h->error_sec = c->error_sec;
h->last_modified = c->last_modified;
h->date = c->date;
h->crc32 = c->crc32;
h.version = NGX_HTTP_CACHE_VERSION;
h.valid_sec = c->valid_sec;
+ h.updating_sec = c->updating_sec;
+ h.error_sec = c->error_sec;
h.last_modified = c->last_modified;
h.date = c->date;
h.crc32 = c->crc32;
case NGX_HTTP_CACHE_UPDATING:
- if (u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING) {
+ if ((u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING)
+ || c->stale_updating)
+ {
u->cache_status = rc;
rc = NGX_OK;
case NGX_HTTP_CACHE_STALE:
c->valid_sec = 0;
+ c->updating_sec = 0;
+ c->error_sec = 0;
+
u->buffer.start = NULL;
u->cache_status = NGX_HTTP_CACHE_EXPIRED;
#if (NGX_HTTP_CACHE)
if (u->cache_status == NGX_HTTP_CACHE_EXPIRED
- && (u->conf->cache_use_stale & un->mask))
+ && ((u->conf->cache_use_stale & un->mask) || r->cache->stale_error))
{
ngx_int_t rc;
&& u->cache_status == NGX_HTTP_CACHE_EXPIRED
&& u->conf->cache_revalidate)
{
- time_t now, valid;
+ time_t now, valid, updating, error;
ngx_int_t rc;
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http upstream not modified");
now = ngx_time();
+
valid = r->cache->valid_sec;
+ updating = r->cache->updating_sec;
+ error = r->cache->error_sec;
rc = u->reinit_request(r);
if (valid == 0) {
valid = r->cache->valid_sec;
+ updating = r->cache->updating_sec;
+ error = r->cache->error_sec;
}
if (valid == 0) {
if (valid) {
r->cache->valid_sec = valid;
+ r->cache->updating_sec = updating;
+ r->cache->error_sec = error;
+
r->cache->date = now;
ngx_http_file_cache_update_header(r);
#if (NGX_HTTP_CACHE)
if (u->cache_status == NGX_HTTP_CACHE_EXPIRED
- && (u->conf->cache_use_stale & ft_type))
+ && ((u->conf->cache_use_stale & ft_type) || r->cache->stale_error))
{
ngx_int_t rc;
offset = 8;
}
- if (p == NULL) {
- return NGX_OK;
- }
+ if (p) {
+ n = 0;
- n = 0;
+ for (p += offset; p < last; p++) {
+ if (*p == ',' || *p == ';' || *p == ' ') {
+ break;
+ }
- for (p += offset; p < last; p++) {
- if (*p == ',' || *p == ';' || *p == ' ') {
- break;
+ if (*p >= '0' && *p <= '9') {
+ n = n * 10 + *p - '0';
+ continue;
+ }
+
+ u->cacheable = 0;
+ return NGX_OK;
}
- if (*p >= '0' && *p <= '9') {
- n = n * 10 + *p - '0';
- continue;
+ if (n == 0) {
+ u->cacheable = 0;
+ return NGX_OK;
}
- u->cacheable = 0;
- return NGX_OK;
+ r->cache->valid_sec = ngx_time() + n;
}
- if (n == 0) {
- u->cacheable = 0;
- return NGX_OK;
+ p = ngx_strlcasestrn(start, last, (u_char *) "stale-while-revalidate=",
+ 23 - 1);
+
+ if (p) {
+ n = 0;
+
+ for (p += 23; p < last; p++) {
+ if (*p == ',' || *p == ';' || *p == ' ') {
+ break;
+ }
+
+ if (*p >= '0' && *p <= '9') {
+ n = n * 10 + *p - '0';
+ continue;
+ }
+
+ u->cacheable = 0;
+ return NGX_OK;
+ }
+
+ r->cache->updating_sec = n;
+ r->cache->error_sec = n;
}
- r->cache->valid_sec = ngx_time() + n;
+ p = ngx_strlcasestrn(start, last, (u_char *) "stale-if-error=", 15 - 1);
+
+ if (p) {
+ n = 0;
+
+ for (p += 15; p < last; p++) {
+ if (*p == ',' || *p == ';' || *p == ' ') {
+ break;
+ }
+
+ if (*p >= '0' && *p <= '9') {
+ n = n * 10 + *p - '0';
+ continue;
+ }
+
+ u->cacheable = 0;
+ return NGX_OK;
+ }
+
+ r->cache->error_sec = n;
+ }
}
#endif