ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.248 by root, Tue Apr 17 18:40:32 2007 UTC vs.
Revision 1.249 by root, Wed Apr 18 12:43:54 2007 UTC

2329sub db_put($$$) { 2329sub db_put($$$) {
2330 BDB::dbreq_pri 4; 2330 BDB::dbreq_pri 4;
2331 BDB::db_put $DB, undef, "$_[0]/$_[1]", Compress::LZF::sfreeze_cr $_[2], 0, sub { }; 2331 BDB::db_put $DB, undef, "$_[0]/$_[1]", Compress::LZF::sfreeze_cr $_[2], 0, sub { };
2332} 2332}
2333 2333
2334=item cf::cache $id => ...
2335
2336Generic caching function that returns the value of the resource $id,
2337caching and regenerating as required.
2338
2339This function can block.
2340
2341 source => filename returning the data (must be a scalar)
2342 expensive => true == try to cache harder
2343 filter => sub that processes the data into a scalar
2344
2345=cut
2346
2347sub cache {
2348 my ($id, %arg) = @_;
2349
2350 aio_stat $arg{source}
2351 and Carp::croak "$arg{source}: $!";
2352
2353 my $meta = join ":", (stat _)[7,9];
2354 my $md5;
2355
2356 if ($arg{expensive}) {
2357 0 <= aio_load $arg{source}, my $buf
2358 or Carp::croak "$arg{source}: $!";
2359
2360 $md5 = Digest::MD5::md5_hex $buf;
2361 }
2362
2363 my $dbmeta = db_get "$id/meta";
2364 if ($dbmeta ne $meta) {
2365 # changed, we need to process
2366 } else {
2367 # just fetch
2368 }
2369
2370
2371}
2372
2334############################################################################# 2373#############################################################################
2335# the server's init and main functions 2374# the server's init and main functions
2336 2375
2337sub load_facedata($) { 2376sub load_facedata($) {
2338 my ($path) = @_; 2377 my ($path) = @_;
2800 prio => 6, 2839 prio => 6,
2801 cb => \&IO::AIO::poll_cb, 2840 cb => \&IO::AIO::poll_cb,
2802 ); 2841 );
2803} 2842}
2804 2843
2844# load additional modules
2845use cf::pod;
2846
2805END { cf::emergency_save } 2847END { cf::emergency_save }
2806 2848
28071 28491
2808 2850

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines