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.

In reply to Re^3: mysql server has gone away & strange behaviour by perrin
in thread mysql server has gone away & strange behaviour by 2ge

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.