@@ -216,6 +216,11 @@ static ngx_uint_t ngx_http_cache_purge_hash_key(ngx_str_t *cache_path,
216216static ngx_http_cache_purge_queue_item_t * ngx_http_cache_purge_find_duplicate (
217217 ngx_http_cache_purge_queue_t * queue , ngx_uint_t hash ,
218218 ngx_str_t * cache_path , ngx_str_t * key );
219+ static ngx_int_t ngx_http_cache_purge_add_variables (ngx_conf_t * cf );
220+ static ngx_int_t ngx_http_cache_purge_queue_size_variable (
221+ ngx_http_request_t * r , ngx_http_variable_value_t * v , uintptr_t data );
222+ static ngx_int_t ngx_http_cache_purge_queue_max_size_variable (
223+ ngx_http_request_t * r , ngx_http_variable_value_t * v , uintptr_t data );
219224
220225# if (NGX_HTTP_FASTCGI )
221226char * ngx_http_fastcgi_cache_purge_conf (ngx_conf_t * cf ,
@@ -301,6 +306,21 @@ char *ngx_http_cache_purge_merge_loc_conf(ngx_conf_t *cf,
301306 void * parent , void * child );
302307
303308
309+ /* -- variable table ----------------------------------------------------- */
310+
311+ static ngx_http_variable_t ngx_http_cache_purge_vars [] = {
312+
313+ { ngx_string ("cache_purge_queue_size" ), NULL ,
314+ ngx_http_cache_purge_queue_size_variable , 0 ,
315+ NGX_HTTP_VAR_NOCACHEABLE , 0 },
316+
317+ { ngx_string ("cache_purge_queue_max_size" ), NULL ,
318+ ngx_http_cache_purge_queue_max_size_variable , 0 ,
319+ NGX_HTTP_VAR_NOCACHEABLE , 0 },
320+
321+ { ngx_null_string , NULL , NULL , 0 , 0 , 0 }
322+ };
323+
304324/* -- module commands ---------------------------------------------------- */
305325
306326static ngx_command_t ngx_http_cache_purge_module_commands [] = {
@@ -382,7 +402,7 @@ static ngx_command_t ngx_http_cache_purge_module_commands[] = {
382402
383403static ngx_http_module_t ngx_http_cache_purge_module_ctx = {
384404 NULL , /* preconfiguration */
385- NULL , /* postconfiguration */
405+ ngx_http_cache_purge_add_variables , /* postconfiguration */
386406 ngx_http_cache_purge_create_main_conf , /* create main conf */
387407 ngx_http_cache_purge_init_main_conf , /* init main conf */
388408 NULL , /* create srv conf */
@@ -411,6 +431,97 @@ static ngx_event_t ngx_cache_purge_event;
411431static ngx_http_cache_purge_main_conf_t * ngx_cache_purge_main_conf ;
412432
413433
434+ /* -- variables ---------------------------------------------------------- */
435+
436+ static ngx_int_t
437+ ngx_http_cache_purge_add_variables (ngx_conf_t * cf )
438+ {
439+ ngx_http_variable_t * var , * v ;
440+
441+ for (v = ngx_http_cache_purge_vars ; v -> name .len ; v ++ ) {
442+ var = ngx_http_add_variable (cf , & v -> name , v -> flags );
443+ if (var == NULL ) {
444+ return NGX_ERROR ;
445+ }
446+ var -> get_handler = v -> get_handler ;
447+ var -> data = v -> data ;
448+ }
449+
450+ return NGX_OK ;
451+ }
452+
453+
454+ static ngx_int_t
455+ ngx_http_cache_purge_queue_size_variable (ngx_http_request_t * r ,
456+ ngx_http_variable_value_t * v , uintptr_t data )
457+ {
458+ ngx_http_cache_purge_main_conf_t * cmcf ;
459+ ngx_uint_t size ;
460+ u_char * p ;
461+ u_char buf [NGX_ATOMIC_T_LEN ];
462+
463+ cmcf = ngx_http_get_module_main_conf (r , ngx_http_cache_purge_module );
464+
465+ if (!cmcf -> background_purge || cmcf -> queue == NULL ) {
466+ v -> data = (u_char * ) "-" ;
467+ v -> len = 1 ;
468+ v -> valid = 1 ;
469+ v -> not_found = 0 ;
470+ return NGX_OK ;
471+ }
472+
473+ size = (ngx_uint_t ) ngx_atomic_fetch_add (& cmcf -> queue -> size , 0 );
474+
475+ p = ngx_sprintf (buf , "%ui" , size );
476+
477+ v -> data = ngx_pnalloc (r -> pool , p - buf );
478+ if (v -> data == NULL ) {
479+ return NGX_ERROR ;
480+ }
481+
482+ ngx_memcpy (v -> data , buf , p - buf );
483+ v -> len = p - buf ;
484+ v -> valid = 1 ;
485+ v -> not_found = 0 ;
486+
487+ return NGX_OK ;
488+ }
489+
490+
491+ static ngx_int_t
492+ ngx_http_cache_purge_queue_max_size_variable (ngx_http_request_t * r ,
493+ ngx_http_variable_value_t * v , uintptr_t data )
494+ {
495+ ngx_http_cache_purge_main_conf_t * cmcf ;
496+ u_char * p ;
497+ u_char buf [NGX_INT_T_LEN ];
498+
499+ cmcf = ngx_http_get_module_main_conf (r , ngx_http_cache_purge_module );
500+
501+ if (!cmcf -> background_purge || cmcf -> queue == NULL ) {
502+ v -> data = (u_char * ) "-" ;
503+ v -> len = 1 ;
504+ v -> valid = 1 ;
505+ v -> not_found = 0 ;
506+ return NGX_OK ;
507+ }
508+
509+ p = ngx_sprintf (buf , "%ui" , cmcf -> queue -> max_size );
510+
511+ v -> data = ngx_pnalloc (r -> pool , p - buf );
512+ if (v -> data == NULL ) {
513+ return NGX_ERROR ;
514+ }
515+
516+ ngx_memcpy (v -> data , buf , p - buf );
517+ v -> len = p - buf ;
518+ v -> valid = 1 ;
519+ v -> not_found = 0 ;
520+
521+ return NGX_OK ;
522+ }
523+
524+
414525/* -- main configuration ------------------------------------------------- */
415526
416527static void *
0 commit comments