/**
  * @group entity
  * @group role
  */
 public function testListAllRolesIsCached()
 {
     $cacheKey = zbase_cache_key(zbase_entity('user_roles'), 'listAllRoles');
     $roles = zbase_entity('user_roles')->listAllRoles();
     $this->assertTrue(is_array($roles));
     $this->assertTrue(zbase_cache_has($cacheKey, [zbase_entity('user_roles')->getTable()], ['driver' => 'file']));
 }
Exemple #2
0
 /**
  * @group entity
  * @group caching
  */
 public function testEntityByAttributeCached()
 {
     $entityName = 'user';
     $attribute = 'username';
     $value = 'adminx';
     $cacheKey = zbase_cache_key(zbase_entity($entityName), 'by_' . $attribute . '_' . $value);
     $this->assertFalse(zbase_cache_has($cacheKey, [zbase_entity($entityName)->getTable()], ['driver' => 'file']));
     $entity = zbase_entity($entityName)->by($attribute, $value);
     $this->assertTrue($entity->{$attribute} == $value);
     $this->assertTrue(zbase_cache_has($cacheKey, [zbase_entity($entityName)->getTable()], ['driver' => 'file']));
     $data = ['username' => 'cacheusernameupdatebyattribute'];
     $entity->fill($data)->save();
     $this->assertFalse(zbase_cache_has($cacheKey, [zbase_entity($entityName)->getTable()], ['driver' => 'file']));
     $data = ['username' => $value];
     $entity->fill($data)->save();
     $this->assertFalse(zbase_cache_has($cacheKey, [zbase_entity($entityName)->getTable()], ['driver' => 'file']));
 }
Exemple #3
0
 /**
  * REturn the number of rows
  * @param array $filters
  * @param array $joins
  * @param array $unions
  * @param array $group
  * @param array $options
  */
 public function count($filters = null, $joins = null, $unions = null, $group = null, $options = null)
 {
     $builder = $this->_query(['COUNT(1)'], $filters, null, $joins, $unions, $group, $options);
     $logMsg = __METHOD__ . PHP_EOL;
     $logMsg .= $this->getSqlStatement($builder) . PHP_EOL;
     $logMsg .= json_encode($this->getSqlBindings($builder)) . PHP_EOL;
     return zbase_cache(zbase_cache_key($this, __FUNCTION__, func_get_args(), $this->getModel()->getTable()), function () use($builder) {
         return $builder->count();
     }, [$this->getModel()->getTable()], null, ['logFile' => 'Repo_' . $this->getModel()->getTable(), 'logMsg' => $logMsg]);
 }
Exemple #4
0
 /**
  * Clear entity cache by Id
  *
  * @return void
  */
 public function clearEntityCacheById()
 {
     $cacheKey = zbase_cache_key(zbase_entity($this->entityName()), 'byId_' . $this->id());
     zbase_cache_remove($cacheKey, [$this->entityName()], ['driver' => 'file']);
     $cacheKey = zbase_cache_key(zbase_entity($this->entityName()), 'byId_' . $this->id() . '_withtrashed');
     zbase_cache_remove($cacheKey, [$this->entityName()], ['driver' => 'file']);
     $cacheKey = zbase_cache_key(zbase_entity($this->entityName()), 'byId_' . $this->id() . '_onlytrashed');
     zbase_cache_remove($cacheKey, [$this->entityName()], ['driver' => 'file']);
 }
Exemple #5
0
 /**
  * Clear entity cache by Attributes/Value
  *
  * @return void
  */
 public function clearPostCacheByTableColumns()
 {
     if (method_exists($this, 'clearCacheByTableColumns')) {
         $this->clearCacheByTableColumns();
     }
     $tableName = $this->postTableName();
     foreach ($this->postTableColumns() as $columnName => $columnConfig) {
         $cacheKey = zbase_cache_key(zbase_entity($tableName), 'by_' . $columnName . '_' . $this->{$columnName});
         zbase_cache_remove($cacheKey, [$tableName], ['driver' => $this->postCacheDriver()]);
     }
 }
Exemple #6
0
 /**
  * Clear entity cache by Id
  *
  * @return void
  */
 public function clearEntityCacheById()
 {
     parent::clearEntityCacheById();
     $cacheKey = zbase_cache_key(zbase_entity($this->entityName()), 'byrelation_address_' . $this->id());
     zbase_cache_remove($cacheKey, [$this->entityName()], ['driver' => 'file']);
     $cacheKey = zbase_cache_key(zbase_entity($this->entityName()), 'byrelation_profile_' . $this->id());
     zbase_cache_remove($cacheKey, [$this->entityName()], ['driver' => 'file']);
 }