What are some techniques for caching a hash? I have a rather large Perl script that tends to get a bit heavy in CPU and memory. To assist in alleviating that, I want to start caching some larger hashes (so they don't remain in memory when not needed).

In PHP, I can just serialize an array and write it to a file in /tmp for a "quick cache" and then load it up later on in the script for the specific functions/methods I need it in. But I can't think of any method in Perl that would resemble that. I'm looking for methods using more of the built in Perl methods and/or default Perl modules.

Do you all do hash caching and if so how do you do it?

Before somebody suggests a third party module: it's important to note I have limited access to Perl modules. Code is on an internal system with no Internet access and the requirements to get *anything* added to even just Perl modules is insane. Not to mention we have no local environment to compile code.

Thanks much!

-- philip
We put the 'K' in kwality!


In reply to Caching a hash? by guice

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.