Greetings, monks. I am having problems using the Cache::FastMmap module in mod_perl 2 and am seeking your wisdom.

I have module MySite::Cache which is included once in the parent apache processes (via PerlModule httpd.conf directive):

package MySite::Cache;
use warnings;
use strict;
use Cache::FastMmap;
use DBI;
our ($dbi_str, $global_cache);
$dbi_str = "DBI:mysql:table;mysql_read_default_file=/path/to/apache.cnf";
$global_cache = new Cache::FastMmap(
  share_file => '/dev/shm/sharefile-global',
  init_file => 1,
  read_cb => sub { &fetch($_[1]); },
  write_cb => sub { $_[2]->store(); },
  delete_cb => sub { &remove($_[1]); },
  #write_action => 'write_back', #ARRRRRRGGGGGGGGHHHHHHHHHHHHH
  empty_on_exit => 1,
  unlink_on_exit => 1,
  expire_time => '1m',
);
chown((getpwnam('apache'))[2,3], '/dev/shm/sharefile-global');
chmod(0660, '/dev/shm/sharefile-global');

sub fetch {
  # super smart code to get database stuffs from key
}

sub remove {
  # really keen code to delete from database by key
}

Every object which is stored in $global_cache has a store() method for write_cb. read_cb and delete_cb are handled by this module.

This all works fine, until I change write_action to write_back. As objects expire from the cache (1m), they just go *poof* to the ether. I've also tried a small cache_size, and once the limit is reached objects are *poof*ed away again. It seems my write_cb is never being called in write_back mode!

Seeking enlightenment,

-userlame

In reply to Using Cache::FastMmap write_back mode by userlame

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.