Example #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);
     }
 }
Example #2
0
 /**
  * @param Metadata $metadata
  * @param QueryBuilder $qb
  * @param Connection $db
  * @param Model $ownerModel
  * @param Relation $ownerField
  */
 public function __construct(Metadata $metadata, QueryBuilder $qb = null, Connection $db = null, Model $ownerModel, Relation $ownerField)
 {
     parent::__construct($metadata, $qb, $db);
     $this->ownerModel = $ownerModel;
     $this->ownerField = $ownerField;
 }