CategoryModel::setCache PHP Method

setCache() public static method

Grab and update the category cache
Since: 2.0.18
public static setCache ( integer | boolean $ID = false, array | boolean $Data = false )
$ID integer | boolean
$Data array | boolean
    public static function setCache($ID = false, $Data = false)
    {
        self::instance()->collection->refreshCache((int) $ID);
        $Categories = Gdn::cache()->get(self::CACHE_KEY);
        self::$Categories = null;
        if (!$Categories) {
            return;
        }
        // Extract actual category list, remove key if malformed
        if (!$ID || !is_array($Categories) || !array_key_exists('categories', $Categories)) {
            Gdn::cache()->remove(self::CACHE_KEY);
            return;
        }
        $Categories = $Categories['categories'];
        // Check for category in list, otherwise remove key if not found
        if (!array_key_exists($ID, $Categories)) {
            Gdn::cache()->remove(self::CACHE_KEY);
            return;
        }
        $Category = $Categories[$ID];
        $Category = array_merge($Category, $Data);
        $Categories[$ID] = $Category;
        // Update memcache entry
        self::$Categories = $Categories;
        unset($Categories);
        self::BuildCache($ID);
        self::JoinUserData(self::$Categories, true);
    }

Usage Example

Example #1
0
 function renderDefault()
 {
     $key = 'category_info_' . $this->template->id_category;
     $this->template->category = CategoryModel::getCache($key);
     if (!$this->template->category) {
         $this->template->category = CategoryModel::getFluent()->where('id_category = %i', $this->template->id_category)->fetch();
         CategoryModel::setCache($key, $this->template->category);
     }
     /*
      * META INFO
      */
     $this['header']->addTitle($this->template->category['meta_title']);
     $this['header']->setDescription($this->template->category['meta_description']);
     $this['header']->addKeywords($this->template->category['meta_keywords']);
 }
All Usage Examples Of CategoryModel::setCache