… | |
… | |
2329 | sub db_put($$$) { |
2329 | sub 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 | |
|
|
2336 | Generic caching function that returns the value of the resource $id, |
|
|
2337 | caching and regenerating as required. |
|
|
2338 | |
|
|
2339 | This 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 | |
|
|
2347 | sub 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 | |
2337 | sub load_facedata($) { |
2376 | sub 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 |
|
|
2845 | use cf::pod; |
|
|
2846 | |
2805 | END { cf::emergency_save } |
2847 | END { cf::emergency_save } |
2806 | |
2848 | |
2807 | 1 |
2849 | 1 |
2808 | |
2850 | |