@@ -7,19 +7,32 @@ Nette Caching
7
7
[ ![ Latest Stable Version] ( https://poser.pugx.org/nette/caching/v/stable )] ( https://github.com/nette/caching/releases )
8
8
[ ![ License] ( https://img.shields.io/badge/license-New%20BSD-blue.svg )] ( https://github.com/nette/caching/blob/master/license.md )
9
9
10
+
11
+ Introduction
12
+ ------------
13
+
10
14
Cache accelerates your application by storing data - once hardly retrieved - for future use.
11
15
12
- Install it using Composer:
16
+ Documentation can be found on the [ website] ( https://doc.nette.org/caching ) .
17
+
18
+
19
+ Installation
20
+ ------------
21
+
22
+ The recommended way to install Nette Caching is via Composer:
13
23
14
24
```
15
25
composer require nette/caching
16
26
```
17
27
18
- The last stable release requires PHP version 5.6 or newer (is compatible with PHP 7.0 and 7.1) . The dev-master version requires PHP 7.1.
28
+ It requires PHP version 5.6 and supports PHP up to 7.2 . The dev-master version requires PHP 7.1.
19
29
20
- Nette offers a very intuitive API for cache manipulation. After all, you wouldn't expect anything else, right? ;-)
21
- Before we show you the first example, we need to think about place where to store data physically. We can use a database, //Memcached// server,
22
- or the most available storage - hard drive:
30
+
31
+ Usage
32
+ -----
33
+
34
+ Nette Caching offers a very intuitive API for cache manipulation. Before we show you the first example, we need to think about place where
35
+ to store data physically. We can use a database, Memcached server, or the most available storage - hard drive:
23
36
24
37
``` php
25
38
// the `temp` directory will be the storage
@@ -82,7 +95,7 @@ $cache = new Cache($storage, 'htmlOutput');
82
95
83
96
84
97
Caching Function Results
85
- -------------------------
98
+ ------------------------
86
99
87
100
Caching the result of a function or method call can be achieved using the ` call() ` method:
88
101
@@ -94,7 +107,7 @@ The `gethostbyaddr($ip)` will therefore be called only once and next time, only
94
107
different results are cached.
95
108
96
109
Output Caching
97
- ------------------
110
+ --------------
98
111
99
112
The output can be cached not only in templates:
100
113
@@ -217,9 +230,8 @@ $cache->clean(array(
217
230
```
218
231
219
232
220
-
221
233
Cache Storage
222
- --------
234
+ -------------
223
235
In addition to already mentioned ` FileStorage ` , Nette Framework also provides ` MemcachedStorage ` which stores
224
236
data to the ` Memcached ` server, and also ` MemoryStorage ` for storing data in memory for duration of the request.
225
237
The special ` DevNullStorage ` , which does precisely nothing, can be used for testing, when we want to eliminate the influence of caching.
@@ -238,8 +250,8 @@ The solution is to modify application behaviour so that data are created only by
238
250
or use an anonymous function:
239
251
240
252
``` php
241
- $result = $cache->save($key, function() { // or callback(...)
242
- return buildData(); // difficult operation
253
+ $result = $cache->save($key, function() {
254
+ return buildData(); // difficult operation
243
255
});
244
256
```
245
257
0 commit comments