0

I want to create a file locker in Magento 2. If i use the default \Magento\Framework\Lock\LockManagerInterface

Magento uses the database to save locks by default. https://devdocs.magento.com/guides/v2.3/install-gde/install/cli/install-cli-subcommands-lock.html

How I can use a fileLock with a custom folder in the var folder?

1

di.xml

<type name="Magento\Framework\Lock\Backend\FileLock">
    <arguments>
        <argument name="path" xsi:type="string">var/lock</argument>
    </arguments>
</type>
<type name="Vendor\ModuleName\Test">
    <arguments>
        <argument name="fileLock" xsi:type="object">Magento\Framework\Lock\Backend\FileLock</argument>
    </arguments>
</type>

Test.php

namespace Vendor\ModuleName;

class Test
{
    /**
     * @var \Magento\Framework\Lock\LockManagerInterface
     */
    private $fileLock;

    /**
     * @var \Magento\Framework\Lock\LockManagerInterface $fileLock
     */
    public function __construct(
        \Magento\Framework\Lock\LockManagerInterface $fileLock,
    ) {
       $this->fileLock = $fileLock;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.