public static function getInstance() { if (self::$instance == null) { self::$instance = new Category_Model(); } return self::$instance; }
/** * 单例模式 * @return Category_Model */ public static function &instance() { if (!isset(self::$instance)) { // Create a new instance self::$instance = new Category_Model(); } return self::$instance; }
/** * 构造函数 */ public function __construct() { //必须继承父类控制器 parent::__construct(); //实例化模型 $this->model = Category_Model::instance(); $this->model->set_from($this->source, $this->appid, $this->device_id, $this->phone_model); $this->_check_request(); }
/** * 执行清空缓存 * @return void */ public function do_task() { if (!empty($this->task_data)) { $user_id = $this->task_data['user_id']; $added_ids = $this->task_data['added_ids']; $updated_ids = $this->task_data['updated_ids']; $deleted_ids = $this->task_data['deleted_ids']; $recycled_ids = $this->task_data['recycled_ids']; $ids = array_merge($added_ids, $updated_ids, $deleted_ids); if ($updated_ids or $recycled_ids or $deleted_ids) { $this->update_cache($user_id, 'recycled_list_update'); } if (!empty($ids) or $this->is_snapshot) { Category_Model::instance()->clear_cache($user_id); } if (!empty($ids)) { foreach ($ids as $id) { $this->cache->delete($this->cache_pre . 'find_by_id_' . $user_id . '_' . $id); } $this->cache->delete($this->cache_pre . 'get_list_' . $user_id); $this->cache->delete($this->cache_pre . 'get_count_' . $user_id); Friend_Model::instance()->del_user_link_cache($user_id); } } }