2008.12.19 - 20:20:02 PDT
This is really getting my goat. I've been stuck here for a day now.
I'm using a module MySite::Cache included as a PerlModule directive in httpd.conf. It implements Cache::FastMmap and makes a global cache for my objects. It looks like this:
So I'm implementing my own read_cb, write_cb, and delete_cb. The objects in the cache always have store() functions to stick themselves into the database. This module knows how to interpret cache keys to make db queries for read_cb and delete_cb.
This all works great, until I try to use write_back mode. Suddenly, the write_cb is never called and objects never store themselves in to the database. When objects are purged due to timeout or size limits, they are not written via the store() method at all. empty_on_exit is not called either. I've tried an empty() call in the DESTROY method of MySite::Cache, but that did not help.
I'll keep digging...
I'm using a module MySite::Cache included as a PerlModule directive in httpd.conf. It implements Cache::FastMmap and makes a global cache for my objects. It looks like this:
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
}
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
}
So I'm implementing my own read_cb, write_cb, and delete_cb. The objects in the cache always have store() functions to stick themselves into the database. This module knows how to interpret cache keys to make db queries for read_cb and delete_cb.
This all works great, until I try to use write_back mode. Suddenly, the write_cb is never called and objects never store themselves in to the database. When objects are purged due to timeout or size limits, they are not written via the store() method at all. empty_on_exit is not called either. I've tried an empty() call in the DESTROY method of MySite::Cache, but that did not help.
I'll keep digging...


