2017 © Pedro Peláez
 

library yiicachemutex

Mutex implementation based on Yii cache component

image

herroffizier/yiicachemutex

Mutex implementation based on Yii cache component

  • Monday, March 17, 2014
  • by herroffizier
  • Repository
  • 1 Watchers
  • 1 Stars
  • 25 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

YiiCacheMutex

YiiCacheMutex is a mutex implementation for Yii framework based on Yii cache component., (*1)

Usage

First, copy files from this repo to extensions/yiicachemutex and add YiiCacheMutex to Yii application:, (*2)

return array(
...
    'components'=>array(
        ...
        'cacheMutex' => array(
            'class' => 'ext.yiicachemutex.YiiCacheMutex',
            // Cache component name.
            // Useful when you want to use separate cache for mutexes.
            'cacheName' => 'cache',
            // Time in microseconds to sleep between cache pollings.
            'sleepTime' => 100,
            // Time in seconds for mutex to expire.
            // If set to 0 mutex will never expire but this is not recommended.
            'expireTime' => 300,
        ),
        ...
    ),
...
);

After that you can create mutexes by calling Yii::app()->cacheMutex->acqiure() and release them by calling Yii::app()->cacheMutex->release(). Mutex acquiring may be blocking or nonblocking. For blocking acquiring a timeout may be set. Also mutexes may have expire time which is highly recommended to avoid deadlocks., (*3)

Usage examples:, (*4)

// Get mutex 'test' if it's free, otherwise wait for it's release forever.
Yii::app()->cacheMutex->acquire('test');

// Get mutex 'test' if it's free, otherwise return false immeditely.
Yii::app()->cacheMutex->acquire('test', 0);

// Wait 0.5s for mutex 'test' to be released.
Yii::app()->cacheMutex->acquire('test', 500000);

// Release acquired by current thread mutex 'test'.
Yii::app()->cacheMutex->release('test');

The Versions

17/03 2014

dev-master

9999999-dev https://github.com/herroffizier/yiicachemutex

Mutex implementation based on Yii cache component

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Martin Stolz

cache yii mutex