Hi,

I'm trying to implement/adopt a "cache" for frequently accessed data which is currently loaded from and stored to files on each access/modification.

Situation

The data loaded from files is represented in hashes (one hash per file). The primary purpose of the "cache" would be to hide the reading/writing of files from the rest of the program, so that data retrieval and modifications stay reasonably fast even when there are high disk loads. The program is a forking server, so the "cache" needs to be shared across multiple processes.

Since I don't see a great overlap between traditional perl caches (CHI, Cache and similar) and my needs (essentially an in(-shared)-memory database with reading and writing entries to files on specific conditions), I don't think using those would be wise.

When trying to implement this "cache" I've considered using some sort of shared-memory module which could store a hash of hashes. On the hash of hashes in shared memory front, I've looked into IPC::MMA and IPC::Shareable but neither seems to fit the bill. IPC::MMA can only store scalars in its hash structures, so I can't nest the hashes. IPC::Shareable has the problem of possible conflicts with the 4 char glue (I need to share lots of relatively simple hashes) and might run out of usable shared memory segments.

I also looked at in-memory databases, but I'm not sure about how that would affect memory usage (I imagine anything in retrieved from a table will be copied), and all databases I've looked at would need a ramdisk, since they don't support in-memory connections from multiple processes.

Question

Primarily, I'd like to ask if you can recommend a perl module which supports nesting hashes in shared memory and doesn't suffer from the limitations IPC::Shareable has, however I'm open to suggestions of alternative approaches to solving my main issue (the "cache").


In reply to Sharing data "cache" between forked processes by Anonymous Monk

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.