httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From luca regini <luca.reg...@gmail.com>
Subject Caching a value for the lifetime of a module: CLUELESS
Date Tue, 08 Mar 2005 10:17:42 GMT
My understanding about per server conf is that any structure allocated
in the server config handler should have a lifetime that is the same
as the one of the module. So the server config structure should be an
ideal place for caching values. Anyway in the following simple module
the dbg counter is correctly incremented only for requests made within
the same connection. When i close the brower, reopen it and make
another request, dbg is set to 0. I am clueless and don't understand
what is wrong with this code.
Thanks in advance for your attention,
Luca


typedef struct
{
	//apr_hash_t *url_ht;
	#ifdef DBG_print_cache
	int dbg;
	#endif

} server_config;



/* Declare the module name */
module AP_MODULE_DECLARE_DATA sds_debug_module;


static void log(char * log)
{
	fprintf(stderr,log);
	fflush(stderr);

}

static void *create_server_config(apr_pool_t *p,server_rec *s)
{
	server_config *sconf = apr_palloc(p,sizeof(*sconf));
	//sconf->url_ht= apr_hash_make(p);
	#ifdef DBG_create_server_config
	fprintf(stderr,"calling create_server_config \n");
	fflush(stderr);
	sconf->dbg=0;
	#endif
	return (void *) sconf;
}


static void print_cache(request_rec *r)
{
	#ifdef DBG_print_cache
	server_config *conf;
	conf=(server_config*)
ap_get_module_config(r->server->module_config,&sds_debug_module);
	fprintf(stderr,"DBG: %d\n",conf->dbg);
	fflush(stderr);
	conf->dbg++;
	#endif
}



static int cache_url_handler(request_rec *r, int lookup)
{
	print_cache(r);
	return DECLINED;
}


/* Register the filter function as a filter for modifying the HTTP
body (content) */
static void register_hooks(apr_pool_t *p)
{
    // cache initializer
    // cache handler
    ap_hook_quick_handler(cache_url_handler, NULL, NULL, APR_HOOK_FIRST);
    // cache filters
    // XXX The cache filters need to run right after the handlers and before
    // any other filters. Consider creating AP_FTYPE_CACHE for this purpose.
    // Make them AP_FTYPE_CONTENT for now.
    // XXX ianhH:they should run AFTER all the other content filters.
    //

}

/* Define the module data */
module AP_MODULE_DECLARE_DATA sds_debug_module =
{
  STANDARD20_MODULE_STUFF,
  NULL,                        /* dir config creater */
  NULL,                        /* dir merger --- default is to override */
  create_server_config,        /* server config */
  NULL,                        /* merge server config */
  NULL,                        /* command apr_table_t */
  register_hooks 	       /* register hook */
};

Mime
View raw message