Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.15.12 ]​[ nginx-1.16.0 ]​

0001 
0002 /*
0003  * Copyright (C) Igor Sysoev
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 
0008 #ifndef _NGX_HTTP_CACHE_H_INCLUDED_
0009 #define _NGX_HTTP_CACHE_H_INCLUDED_
0010 
0011 
0012 #include <ngx_config.h>
0013 #include <ngx_core.h>
0014 #include <ngx_http.h>
0015 
0016 
0017 #define NGX_HTTP_CACHE_MISS          1
0018 #define NGX_HTTP_CACHE_BYPASS        2
0019 #define NGX_HTTP_CACHE_EXPIRED       3
0020 #define NGX_HTTP_CACHE_STALE         4
0021 #define NGX_HTTP_CACHE_UPDATING      5
0022 #define NGX_HTTP_CACHE_REVALIDATED   6
0023 #define NGX_HTTP_CACHE_HIT           7
0024 #define NGX_HTTP_CACHE_SCARCE        8
0025 
0026 #define NGX_HTTP_CACHE_KEY_LEN       16
0027 #define NGX_HTTP_CACHE_ETAG_LEN      128
0028 #define NGX_HTTP_CACHE_VARY_LEN      128
0029 
0030 #define NGX_HTTP_CACHE_VERSION       5
0031 
0032 
0033 typedef struct {
0034     ngx_uint_t                       status;
0035     time_t                           valid;
0036 } ngx_http_cache_valid_t;
0037 
0038 
0039 typedef struct {
0040     ngx_rbtree_node_t                node;
0041     ngx_queue_t                      queue;
0042 
0043     u_char                           key[NGX_HTTP_CACHE_KEY_LEN
0044                                          - sizeof(ngx_rbtree_key_t)];
0045 
0046     unsigned                         count:20;
0047     unsigned                         uses:10;
0048     unsigned                         valid_msec:10;
0049     unsigned                         error:10;
0050     unsigned                         exists:1;
0051     unsigned                         updating:1;
0052     unsigned                         deleting:1;
0053     unsigned                         purged:1;
0054                                      /* 10 unused bits */
0055 
0056     ngx_file_uniq_t                  uniq;
0057     time_t                           expire;
0058     time_t                           valid_sec;
0059     size_t                           body_start;
0060     off_t                            fs_size;
0061     ngx_msec_t                       lock_time;
0062 } ngx_http_file_cache_node_t;
0063 
0064 
0065 struct ngx_http_cache_s {
0066     ngx_file_t                       file;
0067     ngx_array_t                      keys;
0068     uint32_t                         crc32;
0069     u_char                           key[NGX_HTTP_CACHE_KEY_LEN];
0070     u_char                           main[NGX_HTTP_CACHE_KEY_LEN];
0071 
0072     ngx_file_uniq_t                  uniq;
0073     time_t                           valid_sec;
0074     time_t                           updating_sec;
0075     time_t                           error_sec;
0076     time_t                           last_modified;
0077     time_t                           date;
0078 
0079     ngx_str_t                        etag;
0080     ngx_str_t                        vary;
0081     u_char                           variant[NGX_HTTP_CACHE_KEY_LEN];
0082 
0083     size_t                           header_start;
0084     size_t                           body_start;
0085     off_t                            length;
0086     off_t                            fs_size;
0087 
0088     ngx_uint_t                       min_uses;
0089     ngx_uint_t                       error;
0090     ngx_uint_t                       valid_msec;
0091     ngx_uint_t                       vary_tag;
0092 
0093     ngx_buf_t                       *buf;
0094 
0095     ngx_http_file_cache_t           *file_cache;
0096     ngx_http_file_cache_node_t      *node;
0097 
0098 #if (NGX_THREADS || NGX_COMPAT)
0099     ngx_thread_task_t               *thread_task;
0100 #endif
0101 
0102     ngx_msec_t                       lock_timeout;
0103     ngx_msec_t                       lock_age;
0104     ngx_msec_t                       lock_time;
0105     ngx_msec_t                       wait_time;
0106 
0107     ngx_event_t                      wait_event;
0108 
0109     unsigned                         lock:1;
0110     unsigned                         waiting:1;
0111 
0112     unsigned                         updated:1;
0113     unsigned                         updating:1;
0114     unsigned                         exists:1;
0115     unsigned                         temp_file:1;
0116     unsigned                         purged:1;
0117     unsigned                         reading:1;
0118     unsigned                         secondary:1;
0119     unsigned                         background:1;
0120 
0121     unsigned                         stale_updating:1;
0122     unsigned                         stale_error:1;
0123 };
0124 
0125 
0126 typedef struct {
0127     ngx_uint_t                       version;
0128     time_t                           valid_sec;
0129     time_t                           updating_sec;
0130     time_t                           error_sec;
0131     time_t                           last_modified;
0132     time_t                           date;
0133     uint32_t                         crc32;
0134     u_short                          valid_msec;
0135     u_short                          header_start;
0136     u_short                          body_start;
0137     u_char                           etag_len;
0138     u_char                           etag[NGX_HTTP_CACHE_ETAG_LEN];
0139     u_char                           vary_len;
0140     u_char                           vary[NGX_HTTP_CACHE_VARY_LEN];
0141     u_char                           variant[NGX_HTTP_CACHE_KEY_LEN];
0142 } ngx_http_file_cache_header_t;
0143 
0144 
0145 typedef struct {
0146     ngx_rbtree_t                     rbtree;
0147     ngx_rbtree_node_t                sentinel;
0148     ngx_queue_t                      queue;
0149     ngx_atomic_t                     cold;
0150     ngx_atomic_t                     loading;
0151     off_t                            size;
0152     ngx_uint_t                       count;
0153     ngx_uint_t                       watermark;
0154 } ngx_http_file_cache_sh_t;
0155 
0156 
0157 struct ngx_http_file_cache_s {
0158     ngx_http_file_cache_sh_t        *sh;
0159     ngx_slab_pool_t                 *shpool;
0160 
0161     ngx_path_t                      *path;
0162 
0163     off_t                            max_size;
0164     size_t                           bsize;
0165 
0166     time_t                           inactive;
0167 
0168     time_t                           fail_time;
0169 
0170     ngx_uint_t                       files;
0171     ngx_uint_t                       loader_files;
0172     ngx_msec_t                       last;
0173     ngx_msec_t                       loader_sleep;
0174     ngx_msec_t                       loader_threshold;
0175 
0176     ngx_uint_t                       manager_files;
0177     ngx_msec_t                       manager_sleep;
0178     ngx_msec_t                       manager_threshold;
0179 
0180     ngx_shm_zone_t                  *shm_zone;
0181 
0182     ngx_uint_t                       use_temp_path;
0183                                      /* unsigned use_temp_path:1 */
0184 };
0185 
0186 
0187 ngx_int_t ngx_http_file_cache_new(ngx_http_request_t *r);
0188 ngx_int_t ngx_http_file_cache_create(ngx_http_request_t *r);
0189 void ngx_http_file_cache_create_key(ngx_http_request_t *r);
0190 ngx_int_t ngx_http_file_cache_open(ngx_http_request_t *r);
0191 ngx_int_t ngx_http_file_cache_set_header(ngx_http_request_t *r, u_char *buf);
0192 void ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t *tf);
0193 void ngx_http_file_cache_update_header(ngx_http_request_t *r);
0194 ngx_int_t ngx_http_cache_send(ngx_http_request_t *);
0195 void ngx_http_file_cache_free(ngx_http_cache_t *c, ngx_temp_file_t *tf);
0196 time_t ngx_http_file_cache_valid(ngx_array_t *cache_valid, ngx_uint_t status);
0197 
0198 char *ngx_http_file_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
0199     void *conf);
0200 char *ngx_http_file_cache_valid_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
0201     void *conf);
0202 
0203 
0204 extern ngx_str_t  ngx_http_cache_status[];
0205 
0206 
0207 #endif /* _NGX_HTTP_CACHE_H_INCLUDED_ */