Development

/branches/1.2/lib/helper/CacheHelper.php

You must first sign up to be able to contribute.

root/branches/1.2/lib/helper/CacheHelper.php

Revision 8443, 1.5 kB (checked in by fabien, 6 years ago)

fixed typo (closes #3333)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Rev Date
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * CacheHelper.
13  *
14  * @package    symfony
15  * @subpackage helper
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19
20 /* Usage
21
22 <?php if (!cache('name')): ?>
23
24 ... HTML ...
25
26   <?php cache_save() ?>
27 <?php endif; ?>
28
29 */
30 function cache($name, $lifeTime = 86400)
31 {
32   if (!sfConfig::get('sf_cache'))
33   {
34     return null;
35   }
36
37   $cache = sfContext::getInstance()->getViewCacheManager();
38
39   if (sfConfig::get('symfony.cache.started'))
40   {
41     throw new sfCacheException('Cache already started.');
42   }
43
44   $data = $cache->start($name, $lifeTime);
45
46   if (is_null($data))
47   {
48     sfConfig::set('symfony.cache.started', true);
49     sfConfig::set('symfony.cache.current_name', $name);
50
51     return false;
52   }
53   else
54   {
55     echo $data;
56
57     return true;
58   }
59 }
60
61 function cache_save()
62 {
63   if (!sfConfig::get('sf_cache'))
64   {
65     return null;
66   }
67
68   if (!sfConfig::get('symfony.cache.started'))
69   {
70     throw new sfCacheException('Cache not started.');
71   }
72
73   $data = sfContext::getInstance()->getViewCacheManager()->stop(sfConfig::get('symfony.cache.current_name', ''));
74
75   sfConfig::set('symfony.cache.started', false);
76   sfConfig::set('symfony.cache.current_name', null);
77
78   echo $data;
79 }
80
Note: See TracBrowser for help on using the browser.