Skip to content

Commit f45908c

Browse files
committed
refactor: reduced cache key size by removing unnecessary chunkname component.
1 parent bd83c65 commit f45908c

File tree

6 files changed

+138
-136
lines changed

6 files changed

+138
-136
lines changed

src/ngx_http_lua_balancer.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,15 @@ ngx_http_lua_balancer_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
176176
lscf->balancer.src = value[1];
177177

178178
p = ngx_palloc(cf->pool,
179-
sizeof("balancer_by_lua") + NGX_HTTP_LUA_INLINE_KEY_LEN);
179+
sizeof("balancer_by_lua_") +
180+
NGX_HTTP_LUA_INLINE_KEY_LEN);
180181
if (p == NULL) {
181182
return NGX_CONF_ERROR;
182183
}
183184

184185
lscf->balancer.src_key = p;
185186

186-
p = ngx_copy(p, "balancer_by_lua", sizeof("balancer_by_lua") - 1);
187+
p = ngx_copy(p, "balancer_by_lua_", sizeof("balancer_by_lua_") - 1);
187188
p = ngx_copy(p, NGX_HTTP_LUA_INLINE_TAG, NGX_HTTP_LUA_INLINE_TAG_LEN);
188189
p = ngx_http_lua_digest_hex(p, value[1].data, value[1].len);
189190
*p = '\0';

src/ngx_http_lua_directive.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,15 @@ ngx_http_lua_set_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
272272
filter_data->size = filter.size;
273273

274274
p = ngx_palloc(cf->pool,
275-
sizeof("set_by_lua") + NGX_HTTP_LUA_INLINE_KEY_LEN);
275+
sizeof("set_by_lua_") + NGX_HTTP_LUA_INLINE_KEY_LEN);
276276
if (p == NULL) {
277277
return NGX_CONF_ERROR;
278278
}
279279

280280
filter_data->key = p;
281281
filter_data->ref = LUA_REFNIL;
282282

283-
p = ngx_copy(p, "set_by_lua", sizeof("set_by_lua") - 1);
283+
p = ngx_copy(p, "set_by_lua_", sizeof("set_by_lua_") - 1);
284284
p = ngx_copy(p, NGX_HTTP_LUA_INLINE_TAG, NGX_HTTP_LUA_INLINE_TAG_LEN);
285285
p = ngx_http_lua_digest_hex(p, value[2].data, value[2].len);
286286
*p = '\0';
@@ -515,14 +515,14 @@ ngx_http_lua_rewrite_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
515515
llcf->rewrite_src.value = value[1];
516516

517517
p = ngx_palloc(cf->pool,
518-
chunkname_len + NGX_HTTP_LUA_INLINE_KEY_LEN + 1);
518+
sizeof("rewrite_by_lua_") + NGX_HTTP_LUA_INLINE_KEY_LEN);
519519
if (p == NULL) {
520520
return NGX_CONF_ERROR;
521521
}
522522

523523
llcf->rewrite_src_key = p;
524524

525-
p = ngx_copy(p, chunkname, chunkname_len);
525+
p = ngx_copy(p, "rewrite_by_lua_", sizeof("rewrite_by_lua_") - 1);
526526
p = ngx_copy(p, NGX_HTTP_LUA_INLINE_TAG, NGX_HTTP_LUA_INLINE_TAG_LEN);
527527
p = ngx_http_lua_digest_hex(p, value[1].data, value[1].len);
528528
*p = '\0';
@@ -629,14 +629,14 @@ ngx_http_lua_access_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
629629
llcf->access_src.value = value[1];
630630

631631
p = ngx_palloc(cf->pool,
632-
chunkname_len + NGX_HTTP_LUA_INLINE_KEY_LEN + 1);
632+
sizeof("access_by_lua_") + NGX_HTTP_LUA_INLINE_KEY_LEN);
633633
if (p == NULL) {
634634
return NGX_CONF_ERROR;
635635
}
636636

637637
llcf->access_src_key = p;
638638

639-
p = ngx_copy(p, chunkname, chunkname_len);
639+
p = ngx_copy(p, "access_by_lua_", sizeof("access_by_lua_") - 1);
640640
p = ngx_copy(p, NGX_HTTP_LUA_INLINE_TAG, NGX_HTTP_LUA_INLINE_TAG_LEN);
641641
p = ngx_http_lua_digest_hex(p, value[1].data, value[1].len);
642642
*p = '\0';
@@ -749,14 +749,14 @@ ngx_http_lua_content_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
749749
llcf->content_src.value = value[1];
750750

751751
p = ngx_palloc(cf->pool,
752-
chunkname_len + NGX_HTTP_LUA_INLINE_KEY_LEN + 1);
752+
sizeof("content_by_lua_") + NGX_HTTP_LUA_INLINE_KEY_LEN);
753753
if (p == NULL) {
754754
return NGX_CONF_ERROR;
755755
}
756756

757757
llcf->content_src_key = p;
758758

759-
p = ngx_copy(p, chunkname, chunkname_len);
759+
p = ngx_copy(p, "content_by_lua_", sizeof("content_by_lua_") - 1);
760760
p = ngx_copy(p, NGX_HTTP_LUA_INLINE_TAG, NGX_HTTP_LUA_INLINE_TAG_LEN);
761761
p = ngx_http_lua_digest_hex(p, value[1].data, value[1].len);
762762
*p = '\0';
@@ -870,14 +870,14 @@ ngx_http_lua_log_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
870870
llcf->log_src.value = value[1];
871871

872872
p = ngx_palloc(cf->pool,
873-
chunkname_len + NGX_HTTP_LUA_INLINE_KEY_LEN + 1);
873+
sizeof("log_by_lua_") + NGX_HTTP_LUA_INLINE_KEY_LEN);
874874
if (p == NULL) {
875875
return NGX_CONF_ERROR;
876876
}
877877

878878
llcf->log_src_key = p;
879879

880-
p = ngx_copy(p, chunkname, chunkname_len);
880+
p = ngx_copy(p, "log_by_lua_", sizeof("log_by_lua_") - 1);
881881
p = ngx_copy(p, NGX_HTTP_LUA_INLINE_TAG, NGX_HTTP_LUA_INLINE_TAG_LEN);
882882
p = ngx_http_lua_digest_hex(p, value[1].data, value[1].len);
883883
*p = '\0';
@@ -972,16 +972,16 @@ ngx_http_lua_header_filter_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
972972
llcf->header_filter_src.value = value[1];
973973

974974
p = ngx_palloc(cf->pool,
975-
sizeof("header_filter_by_lua") +
975+
sizeof("header_filter_by_lua_") +
976976
NGX_HTTP_LUA_INLINE_KEY_LEN + 1);
977977
if (p == NULL) {
978978
return NGX_CONF_ERROR;
979979
}
980980

981981
llcf->header_filter_src_key = p;
982982

983-
p = ngx_copy(p, "header_filter_by_lua",
984-
sizeof("header_filter_by_lua") - 1);
983+
p = ngx_copy(p, "header_filter_by_lua_",
984+
sizeof("header_filter_by_lua_") - 1);
985985
p = ngx_copy(p, NGX_HTTP_LUA_INLINE_TAG, NGX_HTTP_LUA_INLINE_TAG_LEN);
986986
p = ngx_http_lua_digest_hex(p, value[1].data, value[1].len);
987987
*p = '\0';
@@ -1076,15 +1076,16 @@ ngx_http_lua_body_filter_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
10761076
llcf->body_filter_src.value = value[1];
10771077

10781078
p = ngx_palloc(cf->pool,
1079-
sizeof("body_filter_by_lua") +
1079+
sizeof("body_filter_by_lua_") +
10801080
NGX_HTTP_LUA_INLINE_KEY_LEN + 1);
10811081
if (p == NULL) {
10821082
return NGX_CONF_ERROR;
10831083
}
10841084

10851085
llcf->body_filter_src_key = p;
10861086

1087-
p = ngx_copy(p, "body_filter_by_lua", sizeof("body_filter_by_lua") - 1);
1087+
p = ngx_copy(p, "body_filter_by_lua_",
1088+
sizeof("body_filter_by_lua_") - 1);
10881089
p = ngx_copy(p, NGX_HTTP_LUA_INLINE_TAG, NGX_HTTP_LUA_INLINE_TAG_LEN);
10891090
p = ngx_http_lua_digest_hex(p, value[1].data, value[1].len);
10901091
*p = '\0';

src/ngx_http_lua_ssl_certby.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,16 @@ ngx_http_lua_ssl_cert_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
166166
lscf->srv.ssl_cert_src = value[1];
167167

168168
p = ngx_palloc(cf->pool,
169-
sizeof("ssl_certificate_by_lua") +
169+
sizeof("ssl_certificate_by_lua_") +
170170
NGX_HTTP_LUA_INLINE_KEY_LEN);
171171
if (p == NULL) {
172172
return NGX_CONF_ERROR;
173173
}
174174

175175
lscf->srv.ssl_cert_src_key = p;
176176

177-
p = ngx_copy(p, "ssl_certificate_by_lua",
178-
sizeof("ssl_certificate_by_lua") - 1);
177+
p = ngx_copy(p, "ssl_certificate_by_lua_",
178+
sizeof("ssl_certificate_by_lua_") - 1);
179179
p = ngx_copy(p, NGX_HTTP_LUA_INLINE_TAG, NGX_HTTP_LUA_INLINE_TAG_LEN);
180180
p = ngx_http_lua_digest_hex(p, value[1].data, value[1].len);
181181
*p = '\0';

src/ngx_http_lua_ssl_session_fetchby.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,16 @@ ngx_http_lua_ssl_sess_fetch_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
156156
lscf->srv.ssl_sess_fetch_src = value[1];
157157

158158
p = ngx_palloc(cf->pool,
159-
sizeof("ssl_session_fetch_by_lua") +
159+
sizeof("ssl_session_fetch_by_lua_") +
160160
NGX_HTTP_LUA_INLINE_KEY_LEN);
161161
if (p == NULL) {
162162
return NGX_CONF_ERROR;
163163
}
164164

165165
lscf->srv.ssl_sess_fetch_src_key = p;
166166

167-
p = ngx_copy(p, "ssl_session_fetch_by_lua",
168-
sizeof("ssl_session_fetch_by_lua") - 1);
167+
p = ngx_copy(p, "ssl_session_fetch_by_lua_",
168+
sizeof("ssl_session_fetch_by_lua_") - 1);
169169
p = ngx_copy(p, NGX_HTTP_LUA_INLINE_TAG, NGX_HTTP_LUA_INLINE_TAG_LEN);
170170
p = ngx_http_lua_digest_hex(p, value[1].data, value[1].len);
171171
*p = '\0';

src/ngx_http_lua_ssl_session_storeby.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,16 @@ ngx_http_lua_ssl_sess_store_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
154154
lscf->srv.ssl_sess_store_src = value[1];
155155

156156
p = ngx_palloc(cf->pool,
157-
sizeof("ssl_session_store_by_lua") +
157+
sizeof("ssl_session_store_by_lua_") +
158158
NGX_HTTP_LUA_INLINE_KEY_LEN);
159159
if (p == NULL) {
160160
return NGX_CONF_ERROR;
161161
}
162162

163163
lscf->srv.ssl_sess_store_src_key = p;
164164

165-
p = ngx_copy(p, "ssl_session_store_by_lua",
166-
sizeof("ssl_session_store_by_lua") - 1);
165+
p = ngx_copy(p, "ssl_session_store_by_lua_",
166+
sizeof("ssl_session_store_by_lua_") - 1);
167167
p = ngx_copy(p, NGX_HTTP_LUA_INLINE_TAG, NGX_HTTP_LUA_INLINE_TAG_LEN);
168168
p = ngx_http_lua_digest_hex(p, value[1].data, value[1].len);
169169
*p = '\0';

0 commit comments

Comments
 (0)