.

DataObjectCached Class Reference
[Model]

A Dataobject sub class with build in cache. More...

Inheritance diagram for DataObjectCached:
DataObjectBase IDataObject IActionSource ISearchAdapter IDBTable IDBWhereHolder DataObjectTimestampedCached

List of all members.

Public Member Functions

  fetch ()
  fetches next row into this objects var's

Protected Member Functions

  clear_cache ()
  Remove all items from cache.
  clear_cache_item ($key)
  Clear given cache item.
  compute_cache_item_key ($key)
  Copute global cache key as recurive array string.
  get_cache_item ($key)
  Returns item form cache or NULL if not set.
  get_from_cache ($key, $callback, $params=false)
  Reads a value from cache.
  set_cache_item ($key, $value)
  Sets cache item.

Detailed Description

A Dataobject sub class with build in cache.

Author:
Gerd Riesselmann

Definition at line 10 of file dataobjectcached.cls.php.


Member Function Documentation

DataObjectCached::clear_cache (  )  [protected]

Remove all items from cache.

Definition at line 30 of file dataobjectcached.cls.php.

00030                                          {
00031                 RuntimeCache::remove($this->compute_cache_item_key(''));
00032         }
DataObjectCached::clear_cache_item ( key  )  [protected]

Clear given cache item.

Parameters:
string  $key

Definition at line 39 of file dataobjectcached.cls.php.

00039                                                   {
00040                 RuntimeCache::remove($this->compute_cache_item_key($key));
00041         }
DataObjectCached::compute_cache_item_key ( key  )  [protected]

Copute global cache key as recurive array string.

Parameters:
string  $key
Returns:
string

Definition at line 69 of file dataobjectcached.cls.php.

00069                                                         {
00070                 $ret = $this->to_string();
00071                 if ($ret) {
00072                         if ($key) {
00073                                 $pos = strpos($key, '[');
00074                                 if ($pos === 0) {
00075                                         $ret .= $key;
00076                                 }
00077                                 else if ($pos === false) {
00078                                         $ret .= '[' . $key . ']';
00079                                 }
00080                                 else {
00081                                         $ret .= '[' . substr($key, 0, $pos) . ']' . substr($key, $pos);
00082                                 }
00083                         }
00084                 }
00085                 else {
00086                         $ret = $key;
00087                 }
00088                 return $ret;
00089         }
DataObjectCached::fetch (  ) 

fetches next row into this objects var's

returns true on success false on failure

Example $object = new mytable(); $object->name = "fred"; $object->find(); $store = array(); while ($object->fetch()) { echo $this->ID; $store[] = $object; // builds an array of object lines. }

Returns:
boolean True on success

Reimplemented from DataObjectBase.

Definition at line 108 of file dataobjectcached.cls.php.

00108                             {
00109                 $this->clear_cache();
00110                 return parent::fetch();         
00111     }   
DataObjectCached::get_cache_item ( key  )  [protected]

Returns item form cache or NULL if not set.

Parameters:
string  $key
Returns:
mixed

Definition at line 49 of file dataobjectcached.cls.php.

00049                                                 {
00050                 return RuntimeCache::get($this->compute_cache_item_key($key), null);
00051         }
DataObjectCached::get_from_cache ( key,
callback,
params = false  
) [protected]

Reads a value from cache.

If not already set, cache is populated with result of function $this->$callback

Parameters:
string  $key
string  $callback

Definition at line 18 of file dataobjectcached.cls.php.

00018                                                                             {
00019                 $ret = $this->get_cache_item($key);
00020                 if (is_null($ret)) {
00021                         $ret = $this->$callback($params);
00022                         $this->set_cache_item($key, $ret);
00023                 }
00024                 return $ret;
00025         }
DataObjectCached::set_cache_item ( key,
value  
) [protected]

Sets cache item.

Parameters:
string  $key
mixed  $value

Definition at line 59 of file dataobjectcached.cls.php.

00059                                                         {
00060                 RuntimeCache::set($this->compute_cache_item_key($key), $value);
00061         }

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