Reading from cache instead of MySQL, except the first user who creates it (PHP) -
in web application, many users post data , request calculated result. since calculation time-consuming, want cache result of first user , let other users read cache.
if ( cache::exist( $dataid ) ) { return cache::read( $dataid ); } $result = getdatafromdatabaseandcalcresult( $dataid ); cache::write( $dataid, $result ); return $result;
however, when tried program, more 100 requests come in simultaneously , of them find no cache, call getdatafromdatabaseandcalcresult method. server runs out of cpu resource.
is there idea first user calls getdatafromdatabaseandcalcresult. should implement job-queue or mysql-locking-system or something?
Comments
Post a Comment