| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
function cache($name, $lifeTime = 86400) |
|---|
| 31 |
{ |
|---|
| 32 |
$context = sfContext::getInstance(); |
|---|
| 33 |
|
|---|
| 34 |
if (!sfConfig::get('sf_cache')) |
|---|
| 35 |
{ |
|---|
| 36 |
return null; |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
$request = $context->getRequest(); |
|---|
| 40 |
$cache = $context->getViewCacheManager(); |
|---|
| 41 |
|
|---|
| 42 |
if (!is_null($request->getAttribute('started', null, 'symfony/action/sfAction/cache'))) |
|---|
| 43 |
{ |
|---|
| 44 |
throw new sfCacheException('Cache already started'); |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
$data = $cache->start($name, $lifeTime); |
|---|
| 48 |
|
|---|
| 49 |
if ($data === null) |
|---|
| 50 |
{ |
|---|
| 51 |
$request->setAttribute('started', 1, 'symfony/action/sfAction/cache'); |
|---|
| 52 |
$request->setAttribute('current_name', $name, 'symfony/action/sfAction/cache'); |
|---|
| 53 |
|
|---|
| 54 |
return 0; |
|---|
| 55 |
} |
|---|
| 56 |
else |
|---|
| 57 |
{ |
|---|
| 58 |
echo $data; |
|---|
| 59 |
|
|---|
| 60 |
return 1; |
|---|
| 61 |
} |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
function cache_save() |
|---|
| 65 |
{ |
|---|
| 66 |
$context = sfContext::getInstance(); |
|---|
| 67 |
|
|---|
| 68 |
if (!sfConfig::get('sf_cache')) |
|---|
| 69 |
{ |
|---|
| 70 |
return null; |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
$request = $context->getRequest(); |
|---|
| 74 |
|
|---|
| 75 |
if (is_null($request->getAttribute('started', null, 'symfony/action/sfAction/cache'))) |
|---|
| 76 |
{ |
|---|
| 77 |
throw new sfCacheException('Cache not started'); |
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
$name = $request->getAttribute('current_name', '', 'symfony/action/sfAction/cache'); |
|---|
| 81 |
|
|---|
| 82 |
$data = $context->getViewCacheManager()->stop($name); |
|---|
| 83 |
|
|---|
| 84 |
$request->setAttribute('started', null, 'symfony/action/sfAction/cache'); |
|---|
| 85 |
$request->setAttribute('current_name', null, 'symfony/action/sfAction/cache'); |
|---|
| 86 |
|
|---|
| 87 |
echo $data; |
|---|
| 88 |
} |
|---|
| 89 |
|
|---|