Opened 14 years ago

Last modified 12 years ago

#30 new enhancement

xcache_get_for_update/xcache_lock/xcache_unlock (was Integrated locking system)

Reported by: Martyo Owned by: moo
Priority: trivial Milestone: 5.0.0
Component: cacher Version: 1.2-dev
Keywords: Cc:
Application: PHP Version:
Other Exts: SAPI:
Probability: Blocked By:


I would like x-cache to introduce an integrated locking system. Take for example this inefficient locking method:

while(xcache_get("lock_test"))  { // check if lock exists
	usleep(10); // wait for 10ms
	$waittime += 10; // add wait time to variable
	if($waittime > 10000) { // check if we've been waiting for 10 seconds
xcache_set("lock_test", true); // set the lock
$the_cache_test = xcache_get("test"); // load the test cache into PHP
array_push($the_cache_test, "a test"); // do some stuff here, change $the_cache_test
xcache_set("test", $the_cache_test);
xcache_set("lock_test", false); // unset the lock

Instead of this, I would suggest adding a locking value to xcache_get and xcache_set, like the following:

$new_method = xcache_get("test", true);
array_push($new_method, "the new method");
xcache_set("test", $new_method, false);

The "true" part in xcache_get sets the lock for "test". The "false" part in xcache_set sets the lock for "test" to false. If xcache_get is called and the lock is set, then xcache should sleep for 10ms and check again (this should be defined in the xcache PHP.ini settings)

Change History (3)

comment:2 Changed 14 years ago by moo

  • Milestone changed from 1.1 to 1.2
  • Version set to 1.2-dev

comment:3 Changed 13 years ago by moo

  • Milestone changed from 1.2 to 2.0.0
  • Summary changed from Integrated locking system to xcache_get_for_update() (was Integrated locking system)

comment:4 Changed 13 years ago by moo

  • pending set to 0
  • Summary changed from xcache_get_for_update() (was Integrated locking system) to xcache_get_for_update/xcache_lock/xcache_unlock (was Integrated locking system)

xcache_lock/xcache_unlock is also nice...

Note: See TracTickets for help on using tickets.