Beispiel #1
0
 /**
  * @param QuerySet $q
  * @param int $lifeTime
  * @param Cache $cacheBackend
  */
 public function __construct(QuerySet $q, $lifeTime = 3600, Cache $cacheBackend = null)
 {
     $this->query = $q;
     if ($cacheBackend) {
         $this->cache = $cacheBackend;
     } else {
         $this->cache = new PhpFileCache(DJA_APP_CACHE);
     }
     $cacheKey = $q->_md()->getDbTableName() . '_' . sha1(strval($q));
     if ($this->cache->contains($cacheKey)) {
         $data = $this->cache->fetch($cacheKey);
     } else {
         $data = $this->getData();
         $this->cache->save($cacheKey, $data, $lifeTime);
     }
     $className = $q->_md()->getModelClass();
     foreach ($data as $rowData) {
         $this->data[] = new $className($rowData, false);
     }
 }