| Line | |
|---|
| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /** |
|---|
| 4 | * This class extends Cache_Lite and uses output buffering to get the data to cache. |
|---|
| 5 | * It supports nesting of caches |
|---|
| 6 | * |
|---|
| 7 | * @package Cache_Lite |
|---|
| 8 | * @author Markus Tacker <[email protected]> |
|---|
| 9 | */ |
|---|
| 10 | |
|---|
| 11 | require_once('Cache/Lite/Output.php'); |
|---|
| 12 | |
|---|
| 13 | class Cache_Lite_NestedOutput extends Cache_Lite_Output |
|---|
| 14 | { |
|---|
| 15 | private $nestedIds = array(); |
|---|
| 16 | private $nestedGroups = array(); |
|---|
| 17 | |
|---|
| 18 | /** |
|---|
| 19 | * Start the cache |
|---|
| 20 | * |
|---|
| 21 | * @param string $id cache id |
|---|
| 22 | * @param string $group name of the cache group |
|---|
| 23 | * @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested |
|---|
| 24 | * @return boolean|string false if the cache is not hit else the data |
|---|
| 25 | * @access public |
|---|
| 26 | */ |
|---|
| 27 | function start($id, $group = 'default', $doNotTestCacheValidity = false) |
|---|
| 28 | { |
|---|
| 29 | $this->nestedIds[] = $id; |
|---|
| 30 | $this->nestedGroups[] = $group; |
|---|
| 31 | $data = $this->get($id, $group, $doNotTestCacheValidity); |
|---|
| 32 | if ($data !== false) { |
|---|
| 33 | return $data; |
|---|
| 34 | } |
|---|
| 35 | ob_start(); |
|---|
| 36 | ob_implicit_flush(false); |
|---|
| 37 | return false; |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | /** |
|---|
| 41 | * Stop the cache |
|---|
| 42 | * |
|---|
| 43 | * @param boolen |
|---|
| 44 | * @return string return contents of cache |
|---|
| 45 | */ |
|---|
| 46 | function end() |
|---|
| 47 | { |
|---|
| 48 | $data = ob_get_contents(); |
|---|
| 49 | ob_end_clean(); |
|---|
| 50 | $id = array_pop($this->nestedIds); |
|---|
| 51 | $group = array_pop($this->nestedGroups); |
|---|
| 52 | $this->save($data, $id, $group); |
|---|
| 53 | return $data; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.