master

laravel/framework

Last updated at: 29/12/2023 09:21

Lock.php

TLDR

This file contains an interface Lock that defines methods for acquiring, releasing, and retrieving information about locks in a cache.

Methods

get

Attempt to acquire the lock. This method accepts an optional callback and returns the result of the callback.

block

Attempt to acquire the lock for the given number of seconds. This method accepts the number of seconds and an optional callback, and returns the result of the callback.

release

Release the lock. This method returns a boolean value indicating whether the lock was successfully released.

owner

Returns the current owner of the lock. This method returns a string representing the owner of the lock.

forceRelease

Releases this lock without considering ownership. This method does not return any value.

<?php

namespace Illuminate\Contracts\Cache;

interface Lock
{
    /**
     * Attempt to acquire the lock.
     *
     * @param  callable|null  $callback
     * @return mixed
     */
    public function get($callback = null);

    /**
     * Attempt to acquire the lock for the given number of seconds.
     *
     * @param  int  $seconds
     * @param  callable|null  $callback
     * @return mixed
     */
    public function block($seconds, $callback = null);

    /**
     * Release the lock.
     *
     * @return bool
     */
    public function release();

    /**
     * Returns the current owner of the lock.
     *
     * @return string
     */
    public function owner();

    /**
     * Releases this lock in disregard of ownership.
     *
     * @return void
     */
    public function forceRelease();
}