|
1 | | -.. include:: /Includes.rst.txt |
| 1 | +.. include:: /Includes.rst.txt |
2 | 2 |
|
3 | | -.. _caching-frontend: |
| 3 | +.. _caching-frontend: |
4 | 4 |
|
5 | 5 | =============== |
6 | 6 | Cache frontends |
7 | 7 | =============== |
8 | 8 |
|
| 9 | +A *cache frontend* is the public API for interacting with a cache. It defines |
| 10 | +which value types are accepted and how they are prepared for storage |
| 11 | +(for example serialization or compilation), while delegating persistence to the |
| 12 | +assigned backend. In everyday use, extensions should work with the frontend |
| 13 | +only — direct access to the caching backend is discouraged. |
9 | 14 |
|
10 | | -.. _caching-frontend-api: |
| 15 | +.. _caching-frontend-api: |
11 | 16 |
|
12 | | -Frontend API |
13 | | -============ |
| 17 | +Caching frontend API |
| 18 | +==================== |
14 | 19 |
|
15 | | -All frontends must implement the API defined in interface :code:`TYPO3\CMS\Core\Cache\Frontend\FrontendInterface`. |
16 | | -All operations on a specific cache must be done with these methods. The frontend object of a cache is the main object |
17 | | -any cache manipulation is done with, usually the assigned backend object should not be used directly. |
| 20 | +All caching frontends must implement the interface |
| 21 | +:php:`\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface`. |
18 | 22 |
|
19 | | -.. t3-field-list-table:: |
20 | | - :header-rows: 1 |
| 23 | +.. include:: /CodeSnippets/Manual/Cache/FrontendInterface.rst.txt |
21 | 24 |
|
22 | | - - :Method,30: Method |
23 | | - :Description,70: Description |
| 25 | +The specific cache frontend implementation migth offer additional methods. |
24 | 26 |
|
25 | | - - :Method: |
26 | | - getIdentifier |
27 | | - :Description: |
28 | | - Returns the cache identifier. |
| 27 | +.. _caching-frontend-avalaible: |
29 | 28 |
|
30 | | - - :Method: |
31 | | - getBackend |
32 | | - :Description: |
33 | | - Returns the backend instance of this cache. It is seldom needed in usual code. |
| 29 | +Available cache frontend implementations |
| 30 | +======================================== |
34 | 31 |
|
35 | | - - :Method: |
36 | | - set |
37 | | - :Description: |
38 | | - Sets/overwrites an entry in the cache. |
| 32 | +Two frontends are currently available. They primarily differ in the data |
| 33 | +types they accept and how values are handled before they are passed to |
| 34 | +the backend. |
39 | 35 |
|
40 | | - - :Method: |
41 | | - get |
42 | | - :Description: |
43 | | - Returns the cache entry for the given identifier. |
| 36 | +.. _caching-frontend-variable: |
44 | 37 |
|
45 | | - - :Method: |
46 | | - has |
47 | | - :Description: |
48 | | - Checks for existence of a cache entry. |
49 | | - Do no use this prior to :code:`get()` since :code:`get()` |
50 | | - returns NULL if an entry does not exist. |
51 | | - |
52 | | - - :Method: |
53 | | - remove |
54 | | - :Description: |
55 | | - Removes the entry for the given identifier from the cache. |
56 | | - |
57 | | - - :Method: |
58 | | - flushByTag |
59 | | - :Description: |
60 | | - Flushes all cache entries which are tagged with the given tag. |
61 | | - |
62 | | - - :Method: |
63 | | - collectGarbage |
64 | | - :Description: |
65 | | - Calls the garbage collection method of the backend. |
66 | | - This is important for backends which are unable to do this internally |
67 | | - (like the DB backend). |
68 | | - |
69 | | - - :Method: |
70 | | - isValidEntryIdentifier |
71 | | - :Description: |
72 | | - Checks if a given identifier is valid. |
73 | | - |
74 | | - - :Method: |
75 | | - isValidTag |
76 | | - :Description: |
77 | | - Checks if a given tag is valid. |
78 | | - |
79 | | - - :Method: |
80 | | - requireOnce |
81 | | - :Description: |
82 | | - **PhpFrontend only** Requires a cached PHP file directly. |
83 | | - |
84 | | - |
85 | | -.. _caching-frontend-avalaible: |
| 38 | +Variable frontend |
| 39 | +----------------- |
86 | 40 |
|
87 | | -Available Frontends |
88 | | -=================== |
| 41 | +This frontend accepts strings, arrays, and objects. |
| 42 | +Values are serialized before they are written to the caching backend. |
89 | 43 |
|
90 | | -Currently two different frontends are implemented. The main difference are |
91 | | -the data types which can be stored using a specific frontend. |
| 44 | +It is implemented in :php:`TYPO3\CMS\Core\Cache\Frontend\VariableFrontend`. |
92 | 45 |
|
| 46 | +.. tip:: |
| 47 | + The variable frontend is the most frequently used frontend and handles |
| 48 | + the widest range of data types. |
93 | 49 |
|
94 | | -.. _caching-frontend-variable: |
95 | 50 |
|
96 | | -Variable Frontend |
97 | | ------------------ |
| 51 | +.. _caching-frontend-php: |
98 | 52 |
|
99 | | -Strings, arrays and objects are accepted by this frontend. |
100 | | -Data is serialized before it is passed to the backend. |
| 53 | +PHP frontend |
| 54 | +------------ |
101 | 55 |
|
102 | | -.. tip:: |
103 | | - The variable frontend is the most frequently used frontend and handles |
104 | | - the widest range of data types. |
| 56 | +This frontend is specialized for caching executable PHP files. It adds the |
| 57 | +methods :php:`requireOnce()` and :php:`require()` to load a cached file |
| 58 | +directly. This is useful for extensions that generate PHP code at runtime, |
| 59 | +for example when heavy reflection or dynamic class construction is involved. |
105 | 60 |
|
| 61 | +It is implemented in :php:`TYPO3\CMS\Core\Cache\Frontend\PhpFrontend`. |
106 | 62 |
|
107 | | -.. _caching-frontend-php: |
| 63 | +A backend used with the PHP frontend must implement |
| 64 | +:php:`\TYPO3\CMS\Core\Cache\Backend\PhpCapableBackendInterface`. The file |
| 65 | +backend and the simple file backend currently fulfill this requirement. |
108 | 66 |
|
109 | | -PHP Frontend |
110 | | ------------- |
| 67 | +In addition to the methods defined by |
| 68 | +:php:`\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface`, it provides: |
111 | 69 |
|
112 | | -This is a special frontend to cache PHP files. It extends the string frontend |
113 | | -with the method :code:`requireOnce()` which allows PHP files to be :code:`require()`'d |
114 | | -if a cache entry exists. This can be used by extensions to cache and speed up loading |
115 | | -of calculated PHP code and becomes handy if a lot of reflection and |
116 | | -dynamic PHP class construction is done. |
| 70 | +`requireOnce($entryIdentifier)` |
| 71 | + Loads PHP code from the cache and :php:`require_once` it right away. |
| 72 | +`require(string $entryIdentifier)` |
| 73 | + Loads PHP code from the cache and `require()` it right away. |
117 | 74 |
|
118 | | -A backend to be used in combination with the PHP frontend must implement the interface |
119 | | -:code:`TYPO3\CMS\Core\Cache\Backend\PhpCapableBackendInterface`. Currently the file backend and |
120 | | -the simple file backend fulfill this requirement. |
| 75 | +Unlike `require_once()`, `require()` is safe **only** when the cached code can be |
| 76 | +included multiple times within a single request. Files that declare classes, |
| 77 | +functions, or constants may trigger redeclaration errors. |
121 | 78 |
|
122 | | -.. note:: |
| 79 | +.. note:: |
123 | 80 |
|
124 | | - The PHP frontend can **only** be used to cache PHP files. |
125 | | - It does not work with strings, arrays or objects. |
126 | | - It is **not** intended as a page content cache. |
| 81 | + The PHP caching frontend can **only** be used to cache PHP files. |
| 82 | + It does not work with strings, arrays or objects. |
| 83 | + It is **not** intended as a page content cache. |
0 commit comments