@@ -7,21 +7,33 @@ 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
16
+ Documentation can be found on the [ website] ( https://doc.nette.org/caching ) .
12
17
If you like Nette, ** [ please make a donation now] ( https://nette.org/donate ) ** . Thank you!
13
18
14
- Install it using Composer:
19
+
20
+ Installation
21
+ ------------
22
+
23
+ The recommended way to install Nette Caching is via Composer:
15
24
16
25
```
17
26
composer require nette/caching
18
27
```
19
28
20
- 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.
29
+ It requires PHP version 5.6 and supports PHP up to 7.3 . The dev-master version requires PHP 7.1.
21
30
22
- Nette offers a very intuitive API for cache manipulation. After all, you wouldn't expect anything else, right? ;-)
23
- 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,
24
- or the most available storage - hard drive:
31
+
32
+ Usage
33
+ -----
34
+
35
+ Nette Caching offers a very intuitive API for cache manipulation. Before we show you the first example, we need to think about place where
36
+ to store data physically. We can use a database, Memcached server, or the most available storage - hard drive:
25
37
26
38
``` php
27
39
// the `temp` directory will be the storage
@@ -84,7 +96,7 @@ $cache = new Cache($storage, 'htmlOutput');
84
96
85
97
86
98
Caching Function Results
87
- -------------------------
99
+ ------------------------
88
100
89
101
Caching the result of a function or method call can be achieved using the ` call() ` method:
90
102
@@ -96,7 +108,7 @@ The `gethostbyaddr($ip)` will therefore be called only once and next time, only
96
108
different results are cached.
97
109
98
110
Output Caching
99
- ------------------
111
+ --------------
100
112
101
113
The output can be cached not only in templates:
102
114
@@ -219,9 +231,8 @@ $cache->clean(array(
219
231
```
220
232
221
233
222
-
223
234
Cache Storage
224
- --------
235
+ -------------
225
236
In addition to already mentioned ` FileStorage ` , Nette Framework also provides ` MemcachedStorage ` which stores
226
237
data to the ` Memcached ` server, and also ` MemoryStorage ` for storing data in memory for duration of the request.
227
238
The special ` DevNullStorage ` , which does precisely nothing, can be used for testing, when we want to eliminate the influence of caching.
@@ -240,8 +251,8 @@ The solution is to modify application behaviour so that data are created only by
240
251
or use an anonymous function:
241
252
242
253
``` php
243
- $result = $cache->save($key, function() { // or callback(...)
244
- return buildData(); // difficult operation
254
+ $result = $cache->save($key, function() {
255
+ return buildData(); // difficult operation
245
256
});
246
257
```
247
258
0 commit comments