.

CachedBlock Class Reference

A block that caches its content. More...

Inheritance diagram for CachedBlock:
BlockBase IBlock IRenderer

List of all members.

Public Member Functions

  __construct ($cache_id, $delegate, $life_time=GyroDate::ONE_DAY)
  Constructor.
  get_content ()
  Get content of block (HTML).
  get_name ()
  Name (used as CSS class).
  get_title ()
  Get title of block (heading).

Protected Member Functions

  read_cache ()
  Restore from cache or write block into cache.

Protected Attributes

  $cache_id
  $cache_read = false
  $delegate
  $life_time

Detailed Description

A block that caches its content.

This blocks renders the IBlock given as $delegate and caches it's output.

Author:
Gerd Riesselmann

Definition at line 10 of file cached.block.cls.php.


Constructor & Destructor Documentation

CachedBlock::__construct ( cache_id,
delegate,
life_time = GyroDate::ONE_DAY  
)

Constructor.

Parameters:
string|array  $cache_id The cache id. "block" always gets prepended
IBlock  $delegate The block which output to cache
int  $life_time Cache duration in seconds

Definition at line 29 of file cached.block.cls.php.

00029                                                                                         {
00030                 $this->delegate = $delegate;
00031                 $this->life_time = $life_time;
00032                 $this->cache_id = Arr::force($cache_id, false);
00033                 array_unshift($this->cache_id, 'block');
00034                 
00035                 parent::__construct('', '', '', $delegate->get_index(), $delegate->get_position());
00036         }

Member Function Documentation

CachedBlock::get_content (  ) 

Get content of block (HTML).

Returns:
string

Reimplemented from BlockBase.

Definition at line 85 of file cached.block.cls.php.

00085                                       {
00086                 $this->read_cache();
00087                 return parent::get_content();           
00088         }
CachedBlock::get_name (  ) 

Name (used as CSS class).

Returns:
string

Reimplemented from BlockBase.

Definition at line 95 of file cached.block.cls.php.

00095                                    {
00096                 $this->read_cache();
00097                 return parent::get_name();              
00098         }       
CachedBlock::get_title (  ) 

Get title of block (heading).

Returns:
string

Reimplemented from BlockBase.

Definition at line 75 of file cached.block.cls.php.

00075                                     {
00076                 $this->read_cache();
00077                 return parent::get_title();
00078         }
CachedBlock::read_cache (  )  [protected]

Restore from cache or write block into cache.

Returns:
void

Definition at line 43 of file cached.block.cls.php.

00043                                         {
00044                 if (!$this->cache_read) {
00045                         $this->cache_read = true;
00046                         $content = '';
00047                         $data = array();
00048                         DB::start_trans();
00049                         $cache = Cache::read($this->cache_id);
00050                         if ($cache) {
00051                                 $content = $cache->get_content_plain();
00052                                 $data = $cache->get_data();
00053                         }
00054                         else {
00055                                 // Put into cache
00056                                 $content = $this->delegate->get_content();
00057                                 $data = array(
00058                                         'title' => $this->delegate->get_title(),
00059                                         'name' => $this->delegate->get_name()
00060                                 );
00061                                 Cache::store($this->cache_id, $content, $this->life_time, $data, false);
00062                         }
00063                         DB::commit();
00064                         $this->set_content($content);
00065                         $this->set_title(Arr::get_item($data, 'title', ''));
00066                         $this->set_name(Arr::get_item($data, 'name', ''));
00067                 }       
00068         }

Member Data Documentation

CachedBlock::$cache_id [protected]

Definition at line 18 of file cached.block.cls.php.

CachedBlock::$cache_read = false [protected]

Definition at line 20 of file cached.block.cls.php.

CachedBlock::$delegate [protected]

Definition at line 14 of file cached.block.cls.php.

CachedBlock::$life_time [protected]

Definition at line 19 of file cached.block.cls.php.


The documentation for this class was generated from the following file: