namespace Friendica\Core\Lock;
use Friendica\Core\Cache;
-use Friendica\Core\Cache\IMemoryCacheDriver;
+use Friendica\Core\Cache\IMemoryCache;
-class CacheLockDriver extends AbstractLockDriver
+class CacheLockDriver extends AbstractLock
{
/**
- * @var \Friendica\Core\Cache\ICacheDriver;
+ * @var \Friendica\Core\Cache\ICache;
*/
private $cache;
/**
* CacheLockDriver constructor.
*
- * @param IMemoryCacheDriver $cache The CacheDriver for this type of lock
+ * @param IMemoryCache $cache The CacheDriver for this type of lock
*/
- public function __construct(IMemoryCacheDriver $cache)
+ public function __construct(IMemoryCache $cache)
{
$this->cache = $cache;
}
public function acquireLock($key, $timeout = 120, $ttl = Cache::FIVE_MINUTES)
{
$got_lock = false;
- $start = time();
+ $start = time();
$cachekey = self::getLockKey($key);
$cachekey = self::getLockKey($key);
if ($override) {
- $this->cache->delete($cachekey);
+ $return = $this->cache->delete($cachekey);
} else {
- $this->cache->compareDelete($cachekey, getmypid());
+ $return = $this->cache->compareDelete($cachekey, getmypid());
}
$this->markRelease($key);
+
+ return $return;
}
/**
public function isLocked($key)
{
$cachekey = self::getLockKey($key);
- $lock = $this->cache->get($cachekey);
+ $lock = $this->cache->get($cachekey);
return isset($lock) && ($lock !== false);
}
/**
- * @param string $key The original key
- * @return string The cache key used for the cache
+ * @param string $key The original key
+ *
+ * @return string The cache key used for the cache
*/
- private static function getLockKey($key) {
+ private static function getLockKey($key)
+ {
return "lock:" . $key;
}
}