sub dbm_save() {
    my($cache_file, $key, $value, $datetime_prefix) = @_;

    use DB_File;
    use Fcntl ':flock';
    use Time::Local;

    my(%database);
    my($db) = tie(%database, 'DB_File', $cache_file, O_CREAT | O_RDWR, 0644);
    unless ($db) {
        die("couldn't init DB '$cache_file': $!\n");
    } else {
        my($fd) = $db->fd();
        unless (open(DATAFILE, "+<&=$fd")) {
            die("couldn't safety open DB '$cache_file': $!\n");
        } else {
            unless (flock(DATAFILE, LOCK_EX)) {
                die("couldn't lock DB '$cache_file': $!\n");
            } else {
	    	if ($datetime_prefix) {
	        	my($sec, $min, $hour, $mday, $month, $year) = (localtime)[0,1,2,3,4,5];
                	$year += 1900;
                	$month++;
			$datetime_prefix = sprintf("%04d%02d%02d%02d%02d%02d\t",
	            $year, $month, $mday, $hour, $min, $sec);
		} else {
			$datetime_prefix = '';
		}
		$key .= chr(0);
                $database{$key} = $datetime_prefix.$value;
            }
            $db->sync();
            close(DATAFILE);
	}
	undef($db);
	untie(%database);
    }
}
