What is the best way to create persistent memcached connections under mod_perl?

别等时光非礼了梦想. 提交于 2020-01-15 12:38:46

问题


I know there is a module like Apache::DBI which allows to use persistent connections to database under mod_perl.

Is there an easy way to make something like this? Could you recommend any memcached pooling package?


回答1:


If you look at Apache::DBI's source code, you'll see that it just puts the database handle in a lexical scoped at the top of the package. It's easy enough to do this for Memcached. Make a new package, with a my $memcached; at the top, then have an init() method make the connection and save it in that lexical. Then have a getConnection() method to fetch the connection in your code. That method needs to check if the connection is still alive and reconnect if needed.

Lastly, setup a PerlChildInitHandler to call init() (see Apache::DBI connect_on_init()).



来源:https://stackoverflow.com/questions/8344162/what-is-the-best-way-to-create-persistent-memcached-connections-under-mod-perl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!