File: index.rst

package info (click to toggle)
php-doctrine-cache 2.2.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 472 kB
  • sloc: php: 1,450; xml: 93; makefile: 23
file content (60 lines) | stat: -rw-r--r-- 1,854 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Deprecation Notice
==================

Please note that doctrine/cache is deprecated and no longer maintained. The last
version to include cache drivers is 1.11. The 2.x major release series only
provides the interfaces for libraries that need to maintain backward
compatibility. For all cache uses, we suggest relying on PSR-6 or PSR-16 instead
and using a cache library that supports those interfaces.

Introduction
============

Doctrine Cache is a library that provides an interface for caching data.
Here is what the ``Cache`` interface looks like.

.. code-block:: php
    namespace Doctrine\Common\Cache;

    interface Cache
    {
        public function fetch($id);
        public function contains($id);
        public function save($id, $data, $lifeTime = 0);
        public function delete($id);
        public function getStats();
    }

Use with PSR-6
==============

If you are using the ``Cache`` interface in your application, then you need to
upgrade your application to use a PSR-6 cache library and wrap the PSR-6
``CacheItemPoolInterface`` into the
``Doctrine\Common\Cache\Psr6\DoctrineProvider`` wrapper:

.. code-block:: php

    use Doctrine\Common\Cache\Psr6\DoctrineProvider;

    $cache = DoctrineProvider::wrap($psr6CachePool);

An implementation of the PSR-6 cache is provided by `"symfony/cache" library
<https://symfony.com/doc/current/components/cache.html>`_ for example, you can install it
via Composer with:

::

    composer require symfony/cache

A full example to setup a filesystem based cache with symfony/cache then looks
like this:

.. code-block:: php

    use Doctrine\Common\Cache\Psr6\DoctrineProvider;
    use Symfony\Component\Cache\Adapter\FilesystemAdapter;

    $cachePool = new FilesystemAdapter();
    $cache = DoctrineProvider::wrap($cachePool);
    // $cache instanceof \Doctrine\Common\Cache\Cache