Changes between Initial Version and Version 2 of Ticket #112


Ignore:
Timestamp:
2007-07-05T16:54:39+02:00 (8 years ago)
Author:
moo
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #112

    • Property Type changed from defect to enhancement
  • Ticket #112 – Description

    initial v2  
    1616    // it worth a lock here to avoid useless yet harmful concurrent load from any slow backend (backend=mysql here).
    1717    $fp = fopen(TMPDIR . "/abc_data.lock", "w");
    18     flock($fp, LOCK_EX);
    19     // check AGAIN after we get the lock
    20     if (!xcache_isset("abc_data", $post_check_ttl)) {
    21       mysql_query .... and get $data
    22       xcache_set("cache", $data, 120);
    23       fclose($fp);
    24       return $data;
    25     }
    26     else {
    27       fclose($fp);
     18    // only one worker update it and other keep on reading, if it's in post-check time
     19    $nb = xcache_isset($name) ? 0 : LOCK_NB;
     20    if (flock($fp, LOCK_EX | $nb)) {
     21      // check AGAIN after we get the lock
     22      if (!xcache_isset($name, $post_check_ttl)) {
     23        mysql_query .... and get $data
     24        xcache_set($name, $data, 120);
     25        fclose($fp);
     26        return $data;
     27      }
     28      else {
     29        fclose($fp);
     30      }
    2831    }
    2932  }
    30   return xcache_get("abc_data");
     33  return xcache_get($name);
    3134}
    3235