You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "P. Asokan" <as...@coolgoose.com> on 2005/03/08 12:27:04 UTC

Re: [apache-modules] Caching a value for the lifetime of a module: CLUELESS

Which operating system you are using? If you are using unix os, this problem may be due to the prefork process which will be created to serve for 
each connection. In that case you may have to use shared memory...

Regards,
Asok

> 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 */
> };
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: apache-modules-unsubscribe@covalent.net
> For additional commands, e-mail: apache-modules-help@covalent.net