|
1 | 1 | Caching |
2 | 2 | ======= |
3 | 3 |
|
4 | | -DoctrineModule provides bridging between |
5 | | -`Laminas\Cache <https://github.com/laminas/laminas-cache>`__ and |
6 | | -`Doctrine\Common\Cache <https://github.com/doctrine/common/tree/master/lib/Doctrine/Common/Cache>`__. |
7 | | -This may be useful in case you want to share configured cache instances |
8 | | -across doctrine, symfony and laminas projects. |
| 4 | +DoctrineModule provides some pre-configured caches using |
| 5 | +`Laminas\Cache <https://github.com/laminas/laminas-cache>`__, which can be utilized |
| 6 | +by either Doctrine ORM or Doctrine ODM. |
9 | 7 |
|
10 | | -You may use ``Laminas\Cache`` within your doctrine-related projects as |
11 | | -following: |
| 8 | +The following caches are available by default: |
| 9 | + |
| 10 | +In-Memory |
| 11 | +~~~~~~~~~ |
| 12 | + |
| 13 | +Provided by ``laminas/laminas-cache-storage-adapter-memory``, you can pull this cache from |
| 14 | +the container under the key ``doctrine.cache.array``. It does not really do any caching and |
| 15 | +suits merely as a proof of concept or for cases, where you do not want to have caching. |
| 16 | + |
| 17 | +Filesystem |
| 18 | +~~~~~~~~~~ |
| 19 | + |
| 20 | +Provided by ``laminas/laminas-cache-storage-adapter-filesystem``, you can pull this cache from |
| 21 | +the container under the key ``doctrine.cache.filesystem``. To override the location for the |
| 22 | +cache storage folder, use the following configuration: |
| 23 | + |
| 24 | +.. code:: php |
| 25 | + return [ |
| 26 | + 'caches' => [ |
| 27 | + 'doctrinemodule.cache.filesystem' => [ |
| 28 | + 'options' => [ |
| 29 | + 'cache_dir' => './data/cache/', |
| 30 | + ], |
| 31 | + ], |
| 32 | + ], |
| 33 | + ]; |
| 34 | +
|
| 35 | +APCu |
| 36 | +~~~~ |
| 37 | + |
| 38 | +This cache requires the additional package ``laminas/laminas-cache-storage-adapter-apcu``, which |
| 39 | +is not installed by default. |
| 40 | + |
| 41 | +You can pull the cache from the container using the key ``doctrine.cache.apcu``. To pass additional |
| 42 | +arguments for configuration, use the following config: |
12 | 43 |
|
13 | 44 | .. code:: php |
| 45 | + return [ |
| 46 | + 'caches' => [ |
| 47 | + 'doctrinemodule.cache.apcu' => [ |
| 48 | + 'options' => [ |
| 49 | +
|
| 50 | + ], |
| 51 | + ], |
| 52 | + ], |
| 53 | + ]; |
14 | 54 |
|
15 | | - $laminasCache = new \Laminas\Cache\Storage\Adapter\Memory(); // any storage adapter is OK here |
16 | | - $doctrineCache = new \DoctrineModule\Cache\LaminasStorageCache($laminasCache); |
17 | | - // now use $doctrineCache as a normal Doctrine\Common\Cache\Cache instance |
| 55 | +Memcached |
| 56 | +~~~~~~~~~ |
18 | 57 |
|
19 | | -You may use ``Doctrine\Common\Cache`` within your Laminas projects as |
20 | | -following: |
| 58 | +This cache requires the additional package ``laminas/laminas-cache-storage-adapter-memcached``, which |
| 59 | +is not installed by default. |
| 60 | + |
| 61 | +You can pull the cache from the container using the key ``doctrine.cache.memcached``. To pass additional |
| 62 | +arguments for configuration, use the following config: |
21 | 63 |
|
22 | 64 | .. code:: php |
| 65 | + return [ |
| 66 | + 'caches' => [ |
| 67 | + 'doctrinemodule.cache.memcached' => [ |
| 68 | + 'options' => [ |
| 69 | + 'servers' => [ |
| 70 | +
|
| 71 | + ], |
| 72 | + ], |
| 73 | + ], |
| 74 | + ], |
| 75 | + ]; |
23 | 76 |
|
24 | | - $doctrineCache = new \Doctrine\Common\Cache\ArrayCache(); // any doctrine cache is OK here |
25 | | - $adapterOptions = new \Laminas\Cache\Storage\Adapter\AdapterOptions(); |
26 | | - $laminasCacheStorage = new \DoctrineModule\Cache\DoctrineCacheStorage($adapterOptions, $doctrineCache); |
27 | | - // now use $laminasCacheStorage as a normal Laminas\Cache\Storage\StorageInterface instance. |
| 77 | +Redis |
| 78 | +~~~~~~~~~ |
| 79 | + |
| 80 | +This cache requires the additional package ``laminas/laminas-cache-storage-adapter-redis``, which |
| 81 | +is not installed by default. |
| 82 | + |
| 83 | +You can pull the cache from the container using the key ``doctrine.cache.redis``. The default config |
| 84 | +will access a Redis server at localhost, port 6379. To pass additional arguments for configuration, |
| 85 | +or to change the default config, use the following config: |
| 86 | + |
| 87 | +.. code:: php |
| 88 | + return [ |
| 89 | + 'caches' => [ |
| 90 | + 'doctrinemodule.cache.redis' => [ |
| 91 | + 'options' => [ |
| 92 | + 'server' => [ |
| 93 | + 'host' => 'localhost', |
| 94 | + 'post' => 6379, |
| 95 | + ], |
| 96 | + ], |
| 97 | + ], |
| 98 | + ], |
| 99 | + ]; |
0 commit comments