3
3
-- @author idevz <zhoujing00k@gmail.com>
4
4
-- version $Id$
5
5
6
- VANILLA_G = _G
7
- VANILLA_REGISTRY = {}
6
+
7
+ -- local helpers = require '/media/psf/g/idevz/code/www/vanilla/framework/0_1_0_rc7/vanilla.v.libs.utils'
8
+ -- function sprint_r( ... )
9
+ -- return helpers.sprint_r(...)
10
+ -- end
11
+
12
+ -- function lprint_r( ... )
13
+ -- local rs = sprint_r(...)
14
+ -- print(rs)
15
+ -- end
16
+
17
+ -- function print_r( ... )
18
+ -- local rs = sprint_r(...)
19
+ -- ngx.say(rs)
20
+ -- end
21
+
8
22
Registry = require (' registry' ):new ()
9
23
10
24
92
106
93
107
94
108
-- +--------------------------------------------------------------------------------+--
95
- local ngx_var = ngx .var
96
- local ngx_req = ngx .req
97
109
init_vanilla = function ()
110
+ local ngx_var = ngx .var
111
+ local ngx_req = ngx .req
98
112
Registry .namespace = ngx_var .APP_NAME
99
113
100
- Registry [' REQ_URI' ] = ngx_var .uri
101
- Registry [' REQ_ARGS' ] = ngx_var .args
102
- Registry [' REQ_ARGS_ARR' ] = ngx_req .get_uri_args ()
103
- Registry [' REQ_HEADERS' ] = ngx_req .get_headers ()
104
- Registry [' APP_CACHE_PURGE' ] = Registry [' REQ_ARGS_ARR' ][' vapurge' ]
114
+ local REQ_Registry = require (' registry' ):new ()
115
+ REQ_Registry .namespace = ngx_var .APP_NAME
116
+
117
+ REQ_Registry [' REQ_URI' ] = ngx_var .uri
118
+ REQ_Registry [' REQ_ARGS' ] = ngx_var .args
119
+ REQ_Registry [' REQ_ARGS_ARR' ] = ngx_req .get_uri_args ()
120
+ REQ_Registry [' REQ_HEADERS' ] = ngx_req .get_headers ()
121
+ REQ_Registry [' APP_CACHE_PURGE' ] = REQ_Registry [' REQ_ARGS_ARR' ][' vapurge' ]
122
+ ngx .ctx .REQ_Registry = REQ_Registry
105
123
106
124
107
125
if Registry [' VANILLA_INIT' ] then return end
@@ -125,34 +143,19 @@ init_vanilla = function ()
125
143
Registry [' VANILLA_INIT' ] = true
126
144
end
127
145
128
- -- local helpers = require '/media/psf/g/idevz/code/www/vanilla/framework/0_1_0_rc7/vanilla.v.libs.utils'
129
- -- function sprint_r( ... )
130
- -- return helpers.sprint_r(...)
131
- -- end
132
-
133
- -- function lprint_r( ... )
134
- -- local rs = sprint_r(...)
135
- -- print(rs)
136
- -- end
137
-
138
- -- function print_r( ... )
139
- -- local rs = sprint_r(...)
140
- -- ngx.say(rs)
141
- -- end
142
-
143
-
144
146
-- +--------------------------------------------------------------------------------+--
145
147
local ngx_re_find = ngx .re .find
146
148
use_page_cache = function ()
149
+ local REQ_Registry = ngx .ctx .REQ_Registry
147
150
local cookie_lib = Registry [' VANILLA_COOKIE_LIB' ]
148
151
local cookie = cookie_lib ()
149
152
local no_cache_uris = Registry [' APP_PAGE_CACHE_CONF' ][' no_cache_uris' ]
150
153
for _ , uri in ipairs (no_cache_uris ) do
151
- if ngx_re_find (Registry [' REQ_URI' ], uri ) ~= nil then return false end
154
+ if ngx_re_find (REQ_Registry [' REQ_URI' ], uri ) ~= nil then return false end
152
155
end
153
- Registry [' COOKIES' ] = cookie :getAll ()
156
+ REQ_Registry [' COOKIES' ] = cookie :getAll ()
154
157
if Registry [' APP_PAGE_CACHE_CONF' ][' cache_on' ] then
155
- if Registry [' COOKIES' ] and Registry [' COOKIES' ][Registry [' APP_PAGE_CACHE_CONF' ][' no_cache_cookie' ]] then return false else return true end
158
+ if REQ_Registry [' COOKIES' ] and REQ_Registry [' COOKIES' ][Registry [' APP_PAGE_CACHE_CONF' ][' no_cache_cookie' ]] then return false else return true end
156
159
else
157
160
return false
158
161
end
@@ -181,25 +184,27 @@ local function build_url_key(args)
181
184
end
182
185
183
186
page_cache = function ()
184
- Registry [' USE_PAGE_CACHE' ] = use_page_cache ()
185
- if not Registry [' USE_PAGE_CACHE' ] then ngx .header [' X-Cache' ] = ' PASSBY' return end
187
+ local ngx_var = ngx .var
188
+ local REQ_Registry = ngx .ctx .REQ_Registry
189
+ REQ_Registry [' USE_PAGE_CACHE' ] = use_page_cache ()
190
+ if not REQ_Registry [' USE_PAGE_CACHE' ] then ngx .header [' X-Cache' ] = ' PASSBY' return end
186
191
local cache_lib = Registry [' VANILLA_CACHE_LIB' ]
187
192
Registry [' page_cache_handle' ] = Registry [' APP_PAGE_CACHE_CONF' ][' cache_handle' ] or ' shared_dict'
188
193
local cache = cache_lib (Registry [' page_cache_handle' ])
189
- Registry [' APP_PAGE_CACHE_KEY' ] = Registry [' REQ_URI' ] .. ngx .encode_args (clean_args (Registry [' REQ_ARGS_ARR' ]))
194
+ REQ_Registry [' APP_PAGE_CACHE_KEY' ] = REQ_Registry [' REQ_URI' ] .. ngx .encode_args (clean_args (REQ_Registry [' REQ_ARGS_ARR' ]))
190
195
191
- if Registry [' APP_CACHE_PURGE' ] then
192
- cache :del (Registry [' APP_PAGE_CACHE_KEY' ])
196
+ if REQ_Registry [' APP_CACHE_PURGE' ] then
197
+ cache :del (REQ_Registry [' APP_PAGE_CACHE_KEY' ])
193
198
ngx .header [' X-Cache' ] = ' XX'
194
199
return
195
200
end
196
201
197
- local rs = cache :get (Registry [' APP_PAGE_CACHE_KEY' ])
202
+ local rs = cache :get (REQ_Registry [' APP_PAGE_CACHE_KEY' ])
198
203
if rs then
199
204
ngx .header [' X-Cache' ] = ' HIT'
200
205
ngx_var .va_cache_status = ' HIT'
201
206
ngx .header [' Power_By' ] = ' Vanilla-Page-Cache'
202
- if ngx_re_find (Registry [' REQ_HEADERS' ][' accept' ], ' json' ) then
207
+ if ngx_re_find (REQ_Registry [' REQ_HEADERS' ][' accept' ], ' json' ) then
203
208
ngx .header [' Content_type' ] = ' application/json'
204
209
else
205
210
ngx .header [' Content_type' ] = ' text/html'
0 commit comments