Esempio n. 1
0
 /**
  * Store the model in the cache
  *
  * @return self
  */
 protected function storeInCache()
 {
     if (!Service::getModelCache()) {
         return $this;
     }
     Service::getModelCache()->save($this);
     return $this;
 }
Esempio n. 2
0
 /**
  * Load the current object's properties from the cache
  * @return bool True if the assignement was successful, false if the model
  *              doesn't exist in the cache
  */
 protected function retrieveFromCache()
 {
     if (!$this->existsInCache()) {
         return false;
     }
     $cachedModel = Service::getModelCache()->get(get_class($this), $this->id);
     $this->copy($cachedModel);
     return true;
 }
Esempio n. 3
0
 /**
  * Collects data for the given Request and Response, so that it can be
  * serialized and stored for later retrieval
  *
  * @param Request    $request   A Request instance
  * @param Response   $response  A Response instance
  * @param \Exception $exception An Exception instance
  */
 public function collect(Request $request, Response $response, \Exception $exception = null)
 {
     $this->data = array('queries' => $this->queries, 'cachedModels' => \Service::getModelCache()->all(), 'cacheFetches' => $this->cacheFetches);
 }
Esempio n. 4
0
 /**
  * @Given that the database is empty
  */
 public static function clearDatabase()
 {
     $db = Database::getInstance();
     // Get an array of the tables in the database, so that we can remove them
     $tables = array_map(function ($val) {
         return current($val);
     }, $db->query('SHOW TABLES'));
     if (count($tables) > 0) {
         $db->execute('SET foreign_key_checks = 0');
         $db->execute('DROP TABLES ' . implode($tables, ','));
         $db->execute('SET foreign_key_checks = 1');
     }
     ScriptHandler::migrateDatabase(null, true);
     if ($modelCache = Service::getModelCache()) {
         $modelCache->clear();
     }
 }