diff src/http/ngx_http_cache.c @ 26:45fe5b98a9de NGINX_0_1_13

nginx 0.1.13 *) Feature: the server_names_hash and server_names_hash_threshold directives. *) Bugfix: the *.domain.tld names in the "server_name" directive did not work. *) Bugfix: the %request_length log parameter logged the incorrect length.
author Igor Sysoev <http://sysoev.ru>
date Tue, 21 Dec 2004 00:00:00 +0300
parents 6f8b0dc0f8dd
children
line wrap: on
line diff
--- a/src/http/ngx_http_cache.c
+++ b/src/http/ngx_http_cache.c
@@ -9,6 +9,7 @@
 #include <ngx_http.h>
 
 
+#if 0
 
 static ngx_http_module_t  ngx_http_cache_module_ctx = {
     NULL,                                  /* pre conf */
@@ -30,9 +31,101 @@ ngx_module_t  ngx_http_cache_module = {
     NULL,                                  /* module directives */
     NGX_HTTP_MODULE,                       /* module type */
     NULL,                                  /* init module */
-    NULL                                   /* init child */
+    NULL                                   /* init process */
 };
 
+#endif
+
+
+static ngx_int_t ngx_http_cache_create(ngx_http_request_t *r)
+{
+    ngx_str_t  *key;
+
+    if (!(r->cache = ngx_pcalloc(r->pool, sizeof(ngx_http_cache_t)))) {
+        return NGX_ERROR;
+    }
+
+    if (ngx_array_init(&r->cache->key, r->pool, 5, sizeof(ngx_str_t))
+                                                                  == NGX_ERROR)
+    {
+        return NGX_ERROR;
+    }
+
+    /* preallocate the primary key */
+
+    if (!(key = ngx_array_push(&r->cache->key))) {
+        return NGX_ERROR;
+    }
+
+    key->len = 0;
+    key->data = NULL;
+
+    /*
+     * we use offsetof() because sizeof() pads the struct size to the int size
+     */
+
+    r->cache->header_size = offsetof(ngx_http_cache_header_t, key);
+
+    r->cache->log = r->connection->log;
+    r->cache->file.log = r->connection->log;
+
+    return NGX_OK;
+}
+
+
+ngx_int_t ngx_http_cache_get(ngx_http_request_t *r, ngx_http_cache_ctx_t *ctx)
+{
+    ngx_str_t         *key;
+    ngx_http_cache_t  *c;
+
+    if (r->cache == NULL) {
+        if (ngx_http_cache_create(r) == NGX_ERROR) {
+            return NGX_ABORT;
+        }
+    }
+
+    c = r->cache;
+    key = c->key.elts;
+
+    if (ctx->primary) {
+        key[0] = ctx->key;
+        c->header_size += ctx->key.len;
+        c->key_len += ctx->key.len;
+        c->buf = ctx->buf;
+
+    } else {
+        if (key[0].len == 0) {
+            key[0] = r->uri;
+            c->header_size += r->uri.len;
+            c->key_len += ctx->key.len;
+        }
+
+        if (!(key = ngx_array_push(&r->cache->key))) {
+            return NGX_ABORT;
+        }
+
+        c->header_size += ctx->key.len;
+        c->key_len += ctx->key.len;
+    }
+
+#if 0
+
+    if (ctx->memory) {
+        ngx_http_memory_cache_get(r, ctx);
+    }
+
+#endif
+
+    if (ctx->file) {
+        return ngx_http_file_cache_get(r, ctx);
+    }
+
+    return NGX_DECLINED;
+}
+
+
+#if 0
+
 
 ngx_http_cache_t *ngx_http_cache_get(ngx_http_cache_hash_t *hash,
                                      ngx_http_cleanup_t *cleanup,
@@ -478,3 +571,6 @@ char *ngx_http_set_cache_slot(ngx_conf_t
 
     return NGX_CONF_OK;
 }
+
+
+#endif