Skip to content

5.数据缓存

刘广财 edited this page Mar 21, 2018 · 5 revisions

增删改查

缓存类的定义请参考 缓存类

注意缓存驱动必须继承接口:\Itxiao6\Databse\CacheInterface

设置缓存驱动(在模型的初始化方法内设置)
    /**
     * 模型
     **/
    class UserModel extends \Itxiao6\Database\Eloquent\Model {
        /**
             * 构造方法
             * */
            public function __construct(array $attributes = [])
            {
                // 实例化数据库容器
                $capsule = new DB;
                // 添加连接到容器内
                $capsule - >addConnection([
                    'driver'    => 'mysql',
                    'host'      => 'localhost',
                    'database'  => 'dbname',
                    'username'  => 'username',
                    'password'  => 'pwd',
                    'charset'   => 'utf8',
                    'collation' => 'utf8_unicode_ci',
                    'prefix'    => '',
                ]);
                $capsule -> bootEloquent();
                # 设置缓存驱动
                $this -> set_cache_driver(new CacheClass());
            }
        /**
         * 定义表名
         * */
        protected $table = 'users';
    }
Clone this wiki locally