Esempio n. 1
0
 /**
  * [[@doctodo method_description:test]].
  *
  * @param [[@doctodo param_type:email]] $email      [[@doctodo param_description:email]]
  * @param boolean                       $hash_email [[@doctodo param_description:hash_email]] [optional]
  *
  * @return [[@doctodo return_type:test]] [[@doctodo return_description:test]]
  */
 public function test($email, $hash_email = true)
 {
     $original = $this->getDefaultImage();
     $this->setDefaultImage(404);
     $url = htmlspecialchars_decode($this->get($email, $hash_email));
     $this->setDefaultImage($original);
     $cacheKey = ['testGravatar', $url];
     $cache = Cacher::get($cacheKey);
     if ($cache) {
         return $cache;
     }
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $url);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl, CURLOPT_HEADER, false);
     curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
     $data = curl_exec($curl);
     $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     curl_close($curl);
     if (!$data || $httpCode !== 200) {
         $result = false;
     } else {
         $result = true;
     }
     Cacher::set($cacheKey, $result, 3600);
     return $result;
 }
Esempio n. 2
0
 /**
  * Flush the cache.
  *
  * @param string $category flush a particular category from cache [optional]
  */
 public function actionFlush($category = null)
 {
     if (is_null($category)) {
         $category = $this->prompt("Category (blank for all): ");
     }
     if (empty($category)) {
         $category = 'all';
     } else {
         $category = ['category', $category];
     }
     Cacher::invalidateGroup($category);
     $this->out("Done!");
 }
Esempio n. 3
0
 /**
  * @inheritdoc
  */
 public function afterDeleteRelation($event)
 {
     parent::afterDeleteRelation($event);
     Cacher::invalidateGroup(['Object', 'relations', $this->parent_object_id]);
     Cacher::invalidateGroup(['Object', 'relations', $this->child_object_id]);
     $parentObject = $this->getParentObject(false);
     $childObject = $this->getChildObject(false);
     $relationshipEvent = new RelationshipEvent(['parentEvent' => $event, 'parentObject' => $parentObject, 'childObject' => $childObject, 'relationship' => $this->relationship]);
     if ($parentObject) {
         $parentObject->objectType->trigger(TypeModule::EVENT_RELATION_DELETE, $relationshipEvent);
     }
     if ($childObject) {
         $childObject->objectType->trigger(TypeModule::EVENT_RELATION_DELETE, $relationshipEvent);
     }
 }
Esempio n. 4
0
 private function checkFailTaken($id, $headId)
 {
     $key = __CLASS__ . __FUNCTION__ . $id;
     $checkResult = Cacher::get($key);
     if (!empty($checkResult) && $checkResult !== $headId) {
         return true;
     }
     Cacher::set($key, $headId, 60 * 10);
     return false;
 }
Esempio n. 5
0
 public function getObjectCacheDependency()
 {
     return Cacher::groupDependency(['Object', $this->primaryKey], 'object');
 }
Esempio n. 6
0
 /**
  * [[@doctodo method_description:clearStatusLogCache]].
  */
 public function clearStatusLogCache()
 {
     Cacher::set([get_called_class(), $this->primaryKey, $this->created], false, 3600);
 }
Esempio n. 7
0
 /**
  * [[@doctodo method_description:handleRelationChange]].
  *
  * @param cascade\components\types\RelationshipEvent $event [[@doctodo param_description:event]]
  */
 public function handleRelationChange(RelationshipEvent $event)
 {
     if (get_class($event->parentObject) === $this->owner->primaryModel) {
         Cacher::invalidateGroup('aros');
     }
 }
Esempio n. 8
0
 /**
  * Get stats.
  *
  * @param [[@doctodo param_type:parentObject]] $parentObject [[@doctodo param_description:parentObject]]
  * @param array                                $options      [[@doctodo param_description:options]] [optional]
  *
  * @return [[@doctodo return_type:getStats]] [[@doctodo return_description:getStats]]
  */
 public function getStats($parentObject, $options = [])
 {
     $cacheKey = [__CLASS__ . '.' . __FUNCTION__, 'parentObject' => $parentObject->primaryKey, 'options' => $options, 'context' => ['user']];
     $stats = Cacher::get($cacheKey);
     if (!$stats) {
         $cacheDependency = $this->getCachingDependency($parentObject);
         $stats = [];
         $stats['total'] = $this->getTotalHours($parentObject, $options);
         if ($parentObject->modelAlias !== ':Individual\\ObjectIndividual') {
             $stats['top_contributors'] = $this->getTopContributors($parentObject, $options);
         } else {
             $stats['top_contributions'] = $this->getTopContributions($parentObject, $options);
         }
         $stats['month_summary'] = $this->getMonthSummary($parentObject, $options);
         Cacher::set($cacheKey, $stats, 0, $cacheDependency);
     }
     return $stats;
 }
Esempio n. 9
0
 /**
  * [[@doctodo method_description:saveCache]].
  */
 public function saveCache()
 {
     if (!isset($this->_statusLog)) {
         return $this;
     }
     $this->_statusLog->lastUpdate = microtime(true);
     Cacher::set(['Instance__StatusLog', $this->model->primaryKey, $this->model->created], $this->_statusLog, 3600);
     return $this;
 }