1. class User extends Model
    2. {
    3. CONST TABLE = 'users';
    4. /**
    5. * @var int 设置缓存时间10s ,0也就是禁止缓存
    6. */
    7. protected $_cache_time = 10;
    8. protected $_connection = 'test';
    9. // 通过字段来设置key 避免整张表全量刷新
    10. // 如评论表 可设置 文章id字段当做 缓存key
    11. // 当评论有变化时 只会刷新当前文章的评论缓存
    12. protected $_cache_key_column = [];
    13. // 设置忽略的字段,这些字段更新时不刷新缓存
    14. protected $_ignore_flush_cache_column = [];
    15. /**
    16. * 设置关系 用户的文章
    17. * @return Model
    18. */
    19. public function articles()
    20. {
    21. return $this->hasMany('id', Article::class, 'user_id');
    22. // 状态为 1 的文章
    23. // return $this->hasMany('id', Article::class, 'user_id')->where('status', 1);
    24. }
    25. }
    1. class Article extends Model
    2. {
    3. CONST TABLE = 'articles';
    4. // 文章浏览数量 更新时不刷新缓存
    5. protected $_ignore_flush_cache_column = ['read_count'];
    6. protected $_connection = 'test';
    7. /**
    8. * 设置关系 用户的文章
    9. * @return Model
    10. */
    11. public function article_tags()
    12. {
    13. return $this->hasMany('id', ArticleTag::class, 'article_id');
    14. }
    15. }