I'm not entirely sure I understand what you're trying to do here, but it seems like you're trying very hard to recreate a filesystem :-).

If you've got a decent database system and OS as well as enough RAM, data for the most recent queries will likely still be in the OS's disk cache, which is in RAM. So access to that through the database will not be horrenduously slower than access to a cached version in memory. On the other hand, the overhead of managing your cached data, making sure it's still current, searching through it and expiring it sensibly will likely be quite considerable and could very well use up more system time than you gain (as well as being a good place for subtle bugs to nest). I'm not saying such a solution is generally bad, it could be very sensible if done well and make your application perform better. But it sounds as if you're optimising prematurely. You should probably finish your application, properly abstracting your data access so that you can add caching later, then profile and optimise at that stage.

All that being said, take a look at Memoize, it may be a quick and simple way of doing what you want. And for reusing opened DBI connections, look at Apache::DBI.


There are ten types of people: those that understand binary and those that don't.

In reply to Re: can a perl script act as a daemon to serve data in its symbol table? by tirwhan
in thread can a perl script act as a daemon to serve data in its symbol table? by leocharre

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.