1<?php
2
3/*
4 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 *
16 * This software consists of voluntary contributions made by many individuals
17 * and is licensed under the MIT license. For more information, see
18 * <http://www.doctrine-project.org>.
19 */
20
21namespace Doctrine\ORM\Cache;
22
23/**
24 * Defines contract for concurrently managed data region.
25 * It should be able to lock an specific cache entry in an atomic operation.
26 *
27 * When a entry is locked another process should not be able to read or write the entry.
28 * All evict operation should not consider locks, even though an entry is locked evict should be able to delete the entry and its lock.
29 *
30 * @since   2.5
31 * @author  Fabio B. Silva <fabio.bat.silva@gmail.com>
32 */
33interface ConcurrentRegion extends Region
34{
35    /**
36     * Attempts to read lock the mapping for the given key.
37     *
38     * @param \Doctrine\ORM\Cache\CacheKey $key The key of the item to lock.
39     *
40     * @return \Doctrine\ORM\Cache\Lock A lock instance or NULL if the lock already exists.
41     *
42     * @throws \Doctrine\ORM\Cache\LockException Indicates a problem accessing the region.
43     */
44    public function lock(CacheKey $key);
45
46    /**
47     * Attempts to read unlock the mapping for the given key.
48     *
49     * @param \Doctrine\ORM\Cache\CacheKey $key  The key of the item to unlock.
50     * @param \Doctrine\ORM\Cache\Lock     $lock The lock previously obtained from {@link readLock}
51     *
52     * @return void
53     *
54     * @throws \Doctrine\ORM\Cache\LockException Indicates a problem accessing the region.
55     */
56    public function unlock(CacheKey $key, Lock $lock);
57}
58