Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 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: CacheHelper.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
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 (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
}