Rev | Line | |
---|
[22587] | 1 | <?php |
---|
| 2 | |
---|
| 3 | /** |
---|
| 4 | * This class extends Cache_Lite and uses output buffering to get the data to cache. |
---|
| 5 | * |
---|
| 6 | * There are some examples in the 'docs/examples' file |
---|
| 7 | * Technical choices are described in the 'docs/technical' file |
---|
| 8 | * |
---|
| 9 | * @package Cache_Lite |
---|
| 10 | * @author Fabien MARTY <fab@php.net> |
---|
| 11 | */ |
---|
| 12 | |
---|
| 13 | require_once('Cache/Lite.php'); |
---|
| 14 | |
---|
| 15 | class Cache_Lite_Output extends Cache_Lite |
---|
| 16 | { |
---|
| 17 | |
---|
| 18 | // --- Public methods --- |
---|
| 19 | |
---|
| 20 | /** |
---|
| 21 | * Constructor |
---|
| 22 | * |
---|
| 23 | * $options is an assoc. To have a look at availables options, |
---|
| 24 | * see the constructor of the Cache_Lite class in 'Cache_Lite.php' |
---|
| 25 | * |
---|
| 26 | * @param array $options options |
---|
| 27 | * @access public |
---|
| 28 | */ |
---|
| 29 | function Cache_Lite_Output($options) |
---|
| 30 | { |
---|
| 31 | $this->Cache_Lite($options); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | /** |
---|
| 35 | * Start the cache |
---|
| 36 | * |
---|
| 37 | * @param string $id cache id |
---|
| 38 | * @param string $group name of the cache group |
---|
| 39 | * @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested |
---|
| 40 | * @return boolean true if the cache is hit (false else) |
---|
| 41 | * @access public |
---|
| 42 | */ |
---|
| 43 | function start($id, $group = 'default', $doNotTestCacheValidity = false) |
---|
| 44 | { |
---|
| 45 | $data = $this->get($id, $group, $doNotTestCacheValidity); |
---|
| 46 | if ($data !== false) { |
---|
| 47 | echo($data); |
---|
| 48 | return true; |
---|
| 49 | } |
---|
| 50 | ob_start(); |
---|
| 51 | ob_implicit_flush(false); |
---|
| 52 | return false; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | /** |
---|
| 56 | * Stop the cache |
---|
| 57 | * |
---|
| 58 | * @access public |
---|
| 59 | */ |
---|
| 60 | function end() |
---|
| 61 | { |
---|
| 62 | $data = ob_get_contents(); |
---|
| 63 | ob_end_clean(); |
---|
| 64 | $this->save($data, $this->_id, $this->_group); |
---|
| 65 | echo($data); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.