CustomDataScopedWorker.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2009 by Denis M. Gabaidulin                             *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 
00020     final class CustomDataScopedWorker extends CacheDaoWorker
00021     {
00022         public function __construct($dao)
00023         {
00024             $this->dao = $dao;
00025             
00026             $this->className = $dao->getObjectName();
00027             
00028             if (($cache = Cache::me()) instanceof WatermarkedPeer)
00029                 $this->watermark =
00030                     $cache->mark($this->className)->getActualWatermark();
00031         }
00032         
00033         public function cacheData(
00034             $key,
00035             $data,
00036             $expires = Cache::EXPIRES_FOREVER
00037         )
00038         {
00039             Cache::me()->mark($this->className)->
00040                 add(
00041                     $this->makeDataKey($key, self::SUFFIX_QUERY),
00042                     $data,
00043                     $expires
00044                 );
00045             
00046             return $data;
00047         }
00048         
00049         public function getCachedData($key)
00050         {
00051             return
00052                 Cache::me()->mark($this->className)->
00053                     get($this->makeDataKey($key, self::SUFFIX_QUERY));
00054         }
00055         
00056         private function makeDataKey($key, $suffix)
00057         {
00058             return
00059                 $this->className
00060                 .$suffix
00061                 .$key
00062                 .$this->watermark
00063                 .$this->getLayerId();
00064         }
00065     }
00066 ?>