master

laravel/framework

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

HasCacheLock.php

TLDR

This file is a trait called HasCacheLock that provides methods for acquiring and restoring cache locks.

Methods

lock

This method is used to acquire a lock instance. It takes the following parameters:

  • $name (string): The name of the lock
  • $seconds (int): The number of seconds the lock will be held for (default: 0)
  • $owner (string|null): The owner of the lock (default: null)

It returns an instance of Illuminate\Contracts\Cache\Lock.

restoreLock

This method is used to restore a lock instance using the owner identifier. It takes the following parameters:

  • $name (string): The name of the lock
  • $owner (string): The owner of the lock

It returns an instance of Illuminate\Contracts\Cache\Lock.

<?php

namespace Illuminate\Cache;

trait HasCacheLock
{
    /**
     * Get a lock instance.
     *
     * @param  string  $name
     * @param  int  $seconds
     * @param  string|null  $owner
     * @return \Illuminate\Contracts\Cache\Lock
     */
    public function lock($name, $seconds = 0, $owner = null)
    {
        return new CacheLock($this, $name, $seconds, $owner);
    }

    /**
     * Restore a lock instance using the owner identifier.
     *
     * @param  string  $name
     * @param  string  $owner
     * @return \Illuminate\Contracts\Cache\Lock
     */
    public function restoreLock($name, $owner)
    {
        return $this->lock($name, 0, $owner);
    }
}