in reply to Re^2: mysql server has gone away & strange behaviour
in thread mysql server has gone away & strange behaviour

It's not exactly a caching issue. Your global variable stays around, since you are running in a persistent environment. After some inactivity, the database disconnects the idle connection. Then your next attempt to use that connection fails. Apache::DBI will fix this for you. You just need to call DBI->connect every time instead of only the first time when your "use lib" is executed. Make that library into a proper Perl5 module with a package declaration, and add a sub to it that makes the DBI->connect call and returns the handle. Apache::DBI will handle caching that connection so that it doesn't have to reconnect if the handle is still active.
  • Comment on Re^3: mysql server has gone away & strange behaviour