userlame has asked for the wisdom of the Perl Monks concerning the following question:

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