Example #1
0
 private function loadCategories()
 {
     if ($this->memCache) {
         $memCacheCategories = $this->memCache->read('categories');
         $memCacheCategoriesBySafeName = $this->memCache->read('categoriesBySafeName');
         $memCacheCategoriesById = $this->memCache->read('categoriesById');
         if ($memCacheCategories && $memCacheCategoriesBySafeName && $memCacheCategoriesById) {
             $this->categories = $memCacheCategories;
             $this->categoriesBySafeName = $memCacheCategoriesBySafeName;
             $this->categoriesById = $memCacheCategoriesById;
             return true;
         }
     }
     //if ($this->isTest) { timer_start('cats'); }
     if (!isset($this->categories)) {
         //$this->categories = HotaruModels\Category::getAllOrderForNavBar();
         $this->categories = \Hotaru\Models2\Category::getAllOrderForNavBar($this);
     }
     // index of categories
     if ($this->categories) {
         // This is like making an index on db, only here it is in memory
         foreach ($this->categories as $category) {
             $this->categoriesBySafeName[$category->category_safe_name] = $category;
             $this->categoriesById[$category->category_id] = $category;
         }
         //if ($this->isTest) { print timer_stop(4, 'cats'); }
         // timetests averaging 0.0009, 0.0010, 0.0013 - Sep 21, 2014
         // timetests avergaing 0.0093, 0.0091, 0.0082 - Sep 24, 2014
     }
     if ($this->memCache) {
         $this->memCache->write('categories', $this->categories, 10000);
         $this->memCache->write('categoriesBySafeName', $this->categoriesBySafeName, 10000);
         $this->memCache->write('categoriesById', $this->categoriesById, 10000);
     }
 }