.

CacheDBImpl Class Reference
[Model]

An implememtation of cache as DB table. More...

Inheritance diagram for CacheDBImpl:
ICachePersister

List of all members.

Public Member Functions

  clear ($cache_keys=NULL)
  Clear the cache.
  is_cached ($cache_keys)
  Returns true, if item is chaced.
  read ($cache_keys)
  Read from cache.
  remove_expired ()
  Removes expired cache entries.
  store ($cache_keys, $content, $cache_life_time, $data= '', $is_compressed=false)
  Store content in cache.

Detailed Description

An implememtation of cache as DB table.

Author:
Gerd Riesselmann

Definition at line 8 of file cache.db.impl.php.


Member Function Documentation

CacheDBImpl::clear ( cache_keys = NULL  ) 

Clear the cache.

Parameters:
Mixed  A set of key params, may be an array or a string. If NULL, all is cleared

Implements ICachePersister.

Definition at line 90 of file cache.db.impl.php.

00090                                                   {
00091                 $dao = new DAOCache();
00092                 if (!empty($cache_keys)) {
00093                         $keys = $this->extract_keys($cache_keys);
00094                         $dao->set_keys($keys, true);
00095                 }
00096                 $dao->delete(DAOCache::WHERE_ONLY);                             
00097         }
CacheDBImpl::is_cached ( cache_keys  ) 

Returns true, if item is chaced.

Implements ICachePersister.

Definition at line 14 of file cache.db.impl.php.

00014                                                {
00015                 $dao = new DAOCache();
00016                 $dao->add_where('content_gzip', DBWhere::OP_NOT_NULL);
00017                 $dao->set_keys($this->extract_keys($cache_keys));
00018                 $dao->add_where('expirationdate', '>', DBFieldDateTime::NOW);
00019                 
00020                 if ($dao->find(DAOCache::AUTOFETCH)) {
00021                         $this->cache_item = $dao;
00022                         return true; 
00023                 }
00024                 else {
00025                         $this->cache_item = false;
00026                         return false;
00027                 }
00028         }
CacheDBImpl::read ( cache_keys  ) 

Read from cache.

Parameters:
Mixed  A set of key params, may be an array or a string
Returns:
ICacheItem The cache as array with members "content" and "data", false if cache is not found

Implements ICachePersister.

Definition at line 36 of file cache.db.impl.php.

00036                                           {
00037                 $dao = new DAOCache();
00038                 $dao->add_where('content_gzip', DBWhere::OP_NOT_NULL);
00039                 $dao->set_keys($this->extract_keys($cache_keys));
00040                 $dao->add_where('expirationdate', '>', DBFieldDateTime::NOW);
00041                 
00042                 if ($dao->find(DAOCache::AUTOFETCH)) {
00043                         return $dao; 
00044                 }
00045                 else {
00046                         return false;
00047                 }
00048         }
CacheDBImpl::remove_expired (  ) 

Removes expired cache entries.

Implements ICachePersister.

Definition at line 117 of file cache.db.impl.php.

00117                                          {
00118                 $dao = new DAOCache();
00119                 $dao->add_where('expirationdate', '<', DBFieldDateTime::NOW);
00120                 $dao->delete(DAOCache::WHERE_ONLY);
00121         }
CacheDBImpl::store ( cache_keys,
content,
cache_life_time,
data = '',
is_compressed = false  
)

Store content in cache.

Parameters:
Mixed  A set of key params, may be an array or a string
string  The cache

Implements ICachePersister.

Definition at line 56 of file cache.db.impl.php.

00056                                                                                                            {
00057                 try {
00058                         // Clear old items
00059                         $this->remove_expired();
00060                         $dao = new DAOCache();
00061                         $dao->set_keys($this->extract_keys($cache_keys));
00062                         $update = $dao->find(DAOCache::AUTOFETCH);
00063                         
00064                         if ($is_compressed) {
00065                                 $dao->set_content_compressed($content);
00066                         }
00067                         else {
00068                                 $dao->set_content_plain($content);
00069                         }
00070                         $dao->data = $data;
00071                         $dao->expirationdate = time() + $cache_life_time;
00072                         if ($update) {
00073                                 $dao->update();
00074                         }
00075                         else {
00076                                 $dao->insert();
00077                         }
00078                 }
00079                 catch (Exception $ex) {
00080                         // If inserting into cache fails, just resume application!
00081                         @error_log($ex->getMessage());                  
00082                 }               
00083         }

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