]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Lock.php
Use direct logic
[friendica.git] / src / Core / Lock.php
index 9892f1f4e4d7e74e2dcab9212da8a09f4943401f..a45490bf3966065990476741e64340910bb78582 100644 (file)
@@ -1,13 +1,13 @@
 <?php
 
-namespace Friendica\Core;
-
 /**
  * @file src/Core/Lock.php
  * @brief Functions for preventing parallel execution of functions
  */
 
-use Friendica\Core\Cache\CacheDriverFactory;
+namespace Friendica\Core;
+
+use Friendica\Factory\CacheDriverFactory;
 use Friendica\Core\Cache\IMemoryCacheDriver;
 
 /**
@@ -47,7 +47,7 @@ class Lock
                                        self::useAutoDriver();
                        }
                } catch (\Exception $exception) {
-                       logger ('Driver \'' . $lock_driver . '\' failed - Fallback to \'useAutoDriver()\'');
+                       Logger::log('Driver \'' . $lock_driver . '\' failed - Fallback to \'useAutoDriver()\'');
                        self::useAutoDriver();
                }
        }
@@ -69,7 +69,7 @@ class Lock
                                self::$driver = new Lock\SemaphoreLockDriver();
                                return;
                        } catch (\Exception $exception) {
-                               logger ('Using Semaphore driver for locking failed: ' . $exception->getMessage());
+                               Logger::log('Using Semaphore driver for locking failed: ' . $exception->getMessage());
                        }
                }
 
@@ -83,7 +83,7 @@ class Lock
                                }
                                return;
                        } catch (\Exception $exception) {
-                               logger('Using Cache driver for locking failed: ' . $exception->getMessage());
+                               Logger::log('Using Cache driver for locking failed: ' . $exception->getMessage());
                        }
                }
 
@@ -110,23 +110,25 @@ class Lock
         *
         * @param string  $key Name of the lock
         * @param integer $timeout Seconds until we give up
+        * @param integer $ttl The Lock lifespan, must be one of the Cache constants
         *
         * @return boolean Was the lock successful?
         */
-       public static function acquire($key, $timeout = 120)
+       public static function acquire($key, $timeout = 120, $ttl = Cache::FIVE_MINUTES)
        {
-               return self::getDriver()->acquireLock($key, $timeout);
+               return self::getDriver()->acquireLock($key, $timeout, $ttl);
        }
 
        /**
         * @brief Releases a lock if it was set by us
         *
-        * @param string $key Name of the lock
+        * @param string $key      Name of the lock
+        * @param bool   $override Overrides the lock to get releases
         * @return void
         */
-       public static function release($key)
+       public static function release($key, $override = false)
        {
-               self::getDriver()->releaseLock($key);
+               self::getDriver()->releaseLock($key, $override);
        }
 
        /**