@@ -31,31 +31,31 @@ Each cache region resides in a specific cache namespace and has its own lifetime
31
31
Notice that when caching collection and queries only identifiers are stored.
32
32
The entity values will be stored in its own region
33
33
34
- Something like below for an entity region :
34
+ Something like below for an entity region:
35
35
36
36
.. code-block :: php
37
37
38
38
<?php
39
39
[
40
- 'region_name:entity_1_hash' => ['id'=> 1, 'name' => 'FooBar', 'associationName'=> null],
41
- 'region_name:entity_2_hash' => ['id'=> 2, 'name' => 'Foo', 'associationName'=> ['id'=> 11]],
42
- 'region_name:entity_3_hash' => ['id'=> 3, 'name' => 'Bar', 'associationName'=> ['id'=> 22]]
40
+ 'region_name:entity_1_hash' => ['id' => 1, 'name' => 'FooBar', 'associationName' => null],
41
+ 'region_name:entity_2_hash' => ['id' => 2, 'name' => 'Foo', 'associationName' => ['id' => 11]],
42
+ 'region_name:entity_3_hash' => ['id' => 3, 'name' => 'Bar', 'associationName' => ['id' => 22]]
43
43
];
44
44
45
45
46
46
If the entity holds a collection that also needs to be cached.
47
- An collection region could look something like :
47
+ An collection region could look something like:
48
48
49
49
.. code-block :: php
50
50
51
51
<?php
52
52
[
53
- 'region_name:entity_1_coll_assoc_name_hash' => ['ownerId'=> 1, 'list' => [1, 2, 3]],
54
- 'region_name:entity_2_coll_assoc_name_hash' => ['ownerId'=> 2, 'list' => [2, 3]],
55
- 'region_name:entity_3_coll_assoc_name_hash' => ['ownerId'=> 3, 'list' => [2, 4]]
53
+ 'region_name:entity_1_coll_assoc_name_hash' => ['ownerId' => 1, 'list' => [1, 2, 3]],
54
+ 'region_name:entity_2_coll_assoc_name_hash' => ['ownerId' => 2, 'list' => [2, 3]],
55
+ 'region_name:entity_3_coll_assoc_name_hash' => ['ownerId' => 3, 'list' => [2, 4]]
56
56
];
57
57
58
- A query region might be something like :
58
+ A query region might be something like:
59
59
60
60
.. code-block :: php
61
61
@@ -93,8 +93,6 @@ Cache region
93
93
``Doctrine\ORM\Cache\Region `` defines a contract for accessing a particular
94
94
cache region.
95
95
96
- `See API Doc <https://www.doctrine-project.org/api/orm/current/Doctrine/ORM/Cache/Region.html >`_.
97
-
98
96
Concurrent cache region
99
97
~~~~~~~~~~~~~~~~~~~~~~~
100
98
@@ -105,17 +103,13 @@ If you want to use an ``READ_WRITE`` cache, you should consider providing your o
105
103
106
104
``Doctrine\ORM\Cache\ConcurrentRegion `` defines a contract for concurrently managed data region.
107
105
108
- `See API Doc <https://www.doctrine-project.org/api/orm/current/Doctrine/ORM/Cache/ConcurrentRegion.html >`_.
109
-
110
106
Timestamp region
111
107
~~~~~~~~~~~~~~~~
112
108
113
109
``Doctrine\ORM\Cache\TimestampRegion ``
114
110
115
111
Tracks the timestamps of the most recent updates to particular entity.
116
112
117
- `See API Doc <https://www.doctrine-project.org/api/orm/current/Doctrine/ORM/Cache/TimestampRegion.html >`_.
118
-
119
113
.. _reference-second-level-cache-mode :
120
114
121
115
Caching mode
@@ -132,7 +126,7 @@ Caching mode
132
126
133
127
* Read Write Cache doesn’t employ any locks but can do reads, inserts, updates and deletes.
134
128
* Good if the application needs to update data rarely.
135
-
129
+
136
130
137
131
* ``READ_WRITE ``
138
132
@@ -147,21 +141,21 @@ Built-in cached persisters
147
141
148
142
Cached persisters are responsible to access cache regions.
149
143
150
- +-----------------------+------------------------------------------------------------------------------------------- +
151
- | Cache Usage | Persister |
152
- +=======================+=========================================================================================== +
153
- | READ_ONLY | Doctrine\\ ORM\\ Cache\\ Persister\\ Entity\\ ReadOnlyCachedEntityPersister |
154
- +-----------------------+------------------------------------------------------------------------------------------- +
155
- | READ_WRITE | Doctrine\\ ORM\\ Cache\\ Persister\\ Entity\\ ReadWriteCachedEntityPersister |
156
- +-----------------------+------------------------------------------------------------------------------------------- +
157
- | NONSTRICT_READ_WRITE | Doctrine\\ ORM\\ Cache\\ Persister\\ Entity\\ NonStrictReadWriteCachedEntityPersister |
158
- +-----------------------+------------------------------------------------------------------------------------------- +
159
- | READ_ONLY | Doctrine\\ ORM\\ Cache\\ Persister\\ Collection\\ ReadOnlyCachedCollectionPersister |
160
- +-----------------------+------------------------------------------------------------------------------------------- +
161
- | READ_WRITE | Doctrine\\ ORM\\ Cache\\ Persister\\ Collection\\ ReadWriteCachedCollectionPersister |
162
- +-----------------------+------------------------------------------------------------------------------------------- +
163
- | NONSTRICT_READ_WRITE | Doctrine\\ ORM\\ Cache\\ Persister\\ Collection\\ NonStrictReadWriteCachedCollectionPersister |
164
- +-----------------------+------------------------------------------------------------------------------------------- +
144
+ +-----------------------+------------------------------------------------------------------------------------------+
145
+ | Cache Usage | Persister |
146
+ +=======================+==========================================================================================+
147
+ | READ_ONLY | `` Doctrine\ORM\Cache\Persister\Entity\ReadOnlyCachedEntityPersister `` |
148
+ +-----------------------+------------------------------------------------------------------------------------------+
149
+ | READ_WRITE | `` Doctrine\ORM\Cache\Persister\Entity\ReadWriteCachedEntityPersister `` |
150
+ +-----------------------+------------------------------------------------------------------------------------------+
151
+ | NONSTRICT_READ_WRITE | `` Doctrine\ORM\Cache\Persister\Entity\NonStrictReadWriteCachedEntityPersister `` |
152
+ +-----------------------+------------------------------------------------------------------------------------------+
153
+ | READ_ONLY | `` Doctrine\ORM\Cache\Persister\Collection\ReadOnlyCachedCollectionPersister `` |
154
+ +-----------------------+------------------------------------------------------------------------------------------+
155
+ | READ_WRITE | `` Doctrine\ORM\Cache\Persister\Collection\ReadWriteCachedCollectionPersister `` |
156
+ +-----------------------+------------------------------------------------------------------------------------------+
157
+ | NONSTRICT_READ_WRITE | `` Doctrine\ORM\Cache\Persister\Collection\NonStrictReadWriteCachedCollectionPersister `` |
158
+ +-----------------------+------------------------------------------------------------------------------------------+
165
159
166
160
Configuration
167
161
-------------
@@ -172,7 +166,7 @@ Enable Second Level Cache
172
166
~~~~~~~~~~~~~~~~~~~~~~~~~
173
167
174
168
To enable the second-level-cache, you should provide a cache factory.
175
- ``\ Doctrine\ORM\Cache\DefaultCacheFactory `` is the default implementation.
169
+ ``Doctrine\ORM\Cache\DefaultCacheFactory `` is the default implementation.
176
170
177
171
.. code-block :: php
178
172
@@ -196,7 +190,7 @@ Cache Factory
196
190
197
191
Cache Factory is the main point of extension.
198
192
199
- It allows you to provide a specific implementation of the following components :
193
+ It allows you to provide a specific implementation of the following components:
200
194
201
195
``QueryCache ``
202
196
stores and retrieves query cache results.
@@ -209,8 +203,6 @@ It allows you to provide a specific implementation of the following components :
209
203
``CollectionHydrator ``
210
204
transforms collections into cache entries and cache entries into collections
211
205
212
- `See API Doc <https://www.doctrine-project.org/api/orm/current/Doctrine/ORM/Cache/DefaultCacheFactory.html >`_.
213
-
214
206
Region Lifetime
215
207
~~~~~~~~~~~~~~~
216
208
@@ -234,7 +226,7 @@ Cache Log
234
226
~~~~~~~~~
235
227
By providing a cache logger you should be able to get information about all cache operations such as hits, misses and puts.
236
228
237
- ``\ Doctrine\ORM\Cache\Logging\StatisticsCacheLogger `` is a built-in implementation that provides basic statistics.
229
+ ``Doctrine\ORM\Cache\Logging\StatisticsCacheLogger `` is a built-in implementation that provides basic statistics.
238
230
239
231
.. code-block :: php
240
232
@@ -269,12 +261,9 @@ By providing a cache logger you should be able to get information about all cach
269
261
$logger->getMissCount();
270
262
271
263
If you want to get more information you should implement
272
- ``\ Doctrine\ORM\Cache\Logging\CacheLogger `` and collect
264
+ ``Doctrine\ORM\Cache\Logging\CacheLogger `` and collect
273
265
all the information you want.
274
266
275
- `See API Doc <https://www.doctrine-project.org/api/orm/current/Doctrine/ORM/Cache/Logging/CacheLogger.html >`_.
276
-
277
-
278
267
Entity cache definition
279
268
-----------------------
280
269
* Entity cache configuration allows you to define the caching strategy and region for an entity.
@@ -330,8 +319,8 @@ level cache region.
330
319
Country :
331
320
type : entity
332
321
cache :
333
- usage : READ_ONLY
334
- region : my_entity_region
322
+ usage : READ_ONLY
323
+ region : my_entity_region
335
324
id :
336
325
id :
337
326
type : integer
@@ -401,7 +390,7 @@ It caches the primary keys of association and cache each element will be cached
401
390
</id >
402
391
403
392
<field name =" name" type =" string" column =" name" />
404
-
393
+
405
394
<many-to-one field =" country" target-entity =" Country" >
406
395
<cache usage =" NONSTRICT_READ_WRITE" />
407
396
@@ -421,7 +410,7 @@ It caches the primary keys of association and cache each element will be cached
421
410
State :
422
411
type : entity
423
412
cache :
424
- usage : NONSTRICT_READ_WRITE
413
+ usage : NONSTRICT_READ_WRITE
425
414
id :
426
415
id :
427
416
type : integer
@@ -439,17 +428,18 @@ It caches the primary keys of association and cache each element will be cached
439
428
country_id :
440
429
referencedColumnName : id
441
430
cache :
442
- usage : NONSTRICT_READ_WRITE
431
+ usage : NONSTRICT_READ_WRITE
443
432
444
433
oneToMany :
445
434
cities :
446
435
targetEntity:City
447
436
mappedBy : state
448
437
cache :
449
- usage : NONSTRICT_READ_WRITE
438
+ usage : NONSTRICT_READ_WRITE
450
439
440
+ .. note ::
451
441
452
- > Note: for this to work, the target entity must also be marked as cacheable.
442
+ for this to work, the target entity must also be marked as cacheable.
453
443
454
444
Cache usage
455
445
~~~~~~~~~~~
@@ -466,8 +456,8 @@ Basic entity cache
466
456
467
457
$country1 = $em->find('Country', 1); // Retrieve item from cache
468
458
469
- $country1->setName(" New Name" );
470
-
459
+ $country1->setName(' New Name' );
460
+
471
461
$em->flush(); // Hit database to update the row and update cache
472
462
473
463
$em->clear(); // Clear entity manager
@@ -492,7 +482,7 @@ Association cache
492
482
$state = $em->find('State', 1);
493
483
494
484
// Hit database to update the row and update cache entry
495
- $state->setName(" New Name" );
485
+ $state->setName(' New Name' );
496
486
$em->persist($state);
497
487
$em->flush();
498
488
@@ -550,7 +540,7 @@ The query cache stores the results of the query but as identifiers, entity value
550
540
->setCacheable(true)
551
541
->getResult();
552
542
553
- $em->clear()
543
+ $em->clear();
554
544
555
545
// Check if query result is valid and load entities from cache
556
546
$result2 = $em->createQuery('SELECT c FROM Country c ORDER BY c.name')
@@ -573,7 +563,7 @@ The Cache Mode controls how a particular query interacts with the second-level c
573
563
/* @var $em \Doctrine\ORM\EntityManager */
574
564
// Will refresh the query cache and all entities the cache as it reads from the database.
575
565
$result1 = $em->createQuery('SELECT c FROM Country c ORDER BY c.name')
576
- ->setCacheMode(Cache::MODE_GET)
566
+ ->setCacheMode(\Doctrine\ORM\ Cache::MODE_GET)
577
567
->setCacheable(true)
578
568
->getResult();
579
569
@@ -597,7 +587,7 @@ Execute the ``UPDATE`` and invalidate ``all cache entries`` using ``Query::HINT_
597
587
<?php
598
588
// Execute and invalidate
599
589
$this->_em->createQuery("UPDATE Entity\Country u SET u.name = 'unknown' WHERE u.id = 1")
600
- ->setHint(Query::HINT_CACHE_EVICT, true)
590
+ ->setHint(\Doctrine\ORM\ Query::HINT_CACHE_EVICT, true)
601
591
->execute();
602
592
603
593
@@ -712,11 +702,11 @@ For performance reasons the cache API does not extract from composite primary ke
712
702
$article = $em->find('Article', $article);
713
703
714
704
// Supported
715
- $id = array( 'source' => 1, 'target' => 2) ;
705
+ $id = [ 'source' => 1, 'target' => 2] ;
716
706
$reference = $em->find('Reference', $id);
717
707
718
708
// NOT Supported
719
- $id = array( 'source' => new Article(1), 'target' => new Article(2)) ;
709
+ $id = [ 'source' => new Article(1), 'target' => new Article(2)] ;
720
710
$reference = $em->find('Reference', $id);
721
711
722
712
Distributed environments
0 commit comments