--- deliantra/server/lib/cf.pm 2007/04/17 18:40:32 1.248 +++ deliantra/server/lib/cf.pm 2007/04/18 12:43:54 1.249 @@ -2331,6 +2331,45 @@ BDB::db_put $DB, undef, "$_[0]/$_[1]", Compress::LZF::sfreeze_cr $_[2], 0, sub { }; } +=item cf::cache $id => ... + +Generic caching function that returns the value of the resource $id, +caching and regenerating as required. + +This function can block. + + source => filename returning the data (must be a scalar) + expensive => true == try to cache harder + filter => sub that processes the data into a scalar + +=cut + +sub cache { + my ($id, %arg) = @_; + + aio_stat $arg{source} + and Carp::croak "$arg{source}: $!"; + + my $meta = join ":", (stat _)[7,9]; + my $md5; + + if ($arg{expensive}) { + 0 <= aio_load $arg{source}, my $buf + or Carp::croak "$arg{source}: $!"; + + $md5 = Digest::MD5::md5_hex $buf; + } + + my $dbmeta = db_get "$id/meta"; + if ($dbmeta ne $meta) { + # changed, we need to process + } else { + # just fetch + } + + +} + ############################################################################# # the server's init and main functions @@ -2802,6 +2841,9 @@ ); } +# load additional modules +use cf::pod; + END { cf::emergency_save } 1