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
23use Doctrine\ORM\Mapping\ClassMetadata;
24use Doctrine\ORM\EntityManagerInterface;
25use Doctrine\ORM\Persisters\Collection\CollectionPersister;
26use Doctrine\ORM\Persisters\Entity\EntityPersister;
27
28/**
29 * Contract for building second level cache regions components.
30 *
31 * @since   2.5
32 * @author  Fabio B. Silva <fabio.bat.silva@gmail.com>
33 */
34interface CacheFactory
35{
36    /**
37     * Build an entity persister for the given entity metadata.
38     *
39     * @param \Doctrine\ORM\EntityManagerInterface            $em        The entity manager.
40     * @param \Doctrine\ORM\Persisters\Entity\EntityPersister $persister The entity persister that will be cached.
41     * @param \Doctrine\ORM\Mapping\ClassMetadata             $metadata  The entity metadata.
42     *
43     * @return \Doctrine\ORM\Cache\Persister\Entity\CachedEntityPersister
44     */
45    public function buildCachedEntityPersister(EntityManagerInterface $em, EntityPersister $persister, ClassMetadata $metadata);
46
47    /**
48     * Build a collection persister for the given relation mapping.
49     *
50     * @param \Doctrine\ORM\EntityManagerInterface                    $em        The entity manager.
51     * @param \Doctrine\ORM\Persisters\Collection\CollectionPersister $persister The collection persister that will be cached.
52     * @param array                                                   $mapping   The association mapping.
53     *
54     * @return \Doctrine\ORM\Cache\Persister\Collection\CachedCollectionPersister
55     */
56    public function buildCachedCollectionPersister(EntityManagerInterface $em, CollectionPersister $persister, array $mapping);
57
58    /**
59     * Build a query cache based on the given region name
60     *
61     * @param \Doctrine\ORM\EntityManagerInterface $em         The Entity manager.
62     * @param string                               $regionName The region name.
63     *
64     * @return \Doctrine\ORM\Cache\QueryCache The built query cache.
65     */
66    public function buildQueryCache(EntityManagerInterface $em, $regionName = null);
67
68    /**
69     * Build an entity hydrator
70     *
71     * @param \Doctrine\ORM\EntityManagerInterface $em       The Entity manager.
72     * @param \Doctrine\ORM\Mapping\ClassMetadata  $metadata The entity metadata.
73     *
74     * @return \Doctrine\ORM\Cache\EntityHydrator The built entity hydrator.
75     */
76    public function buildEntityHydrator(EntityManagerInterface $em, ClassMetadata $metadata);
77
78    /**
79     * Build a collection hydrator
80     *
81     * @param \Doctrine\ORM\EntityManagerInterface $em      The Entity manager.
82     * @param array                                $mapping The association mapping.
83     *
84     * @return \Doctrine\ORM\Cache\CollectionHydrator The built collection hydrator.
85     */
86    public function buildCollectionHydrator(EntityManagerInterface $em, array $mapping);
87
88    /**
89     * Build a cache region
90     *
91     * @param array $cache The cache configuration.
92     *
93     * @return \Doctrine\ORM\Cache\Region The cache region.
94     */
95    public function getRegion(array $cache);
96
97    /**
98     * Build timestamp cache region
99     *
100     * @return \Doctrine\ORM\Cache\TimestampRegion The timestamp region.
101     */
102    public function getTimestampRegion();
103
104    /**
105     * Build \Doctrine\ORM\Cache
106     *
107     * @param EntityManagerInterface $entityManager
108     *
109     * @return \Doctrine\ORM\Cache
110     */
111    public function createCache(EntityManagerInterface $entityManager);
112}
113