heraldboy
V2EX  ›  PHP

php 的 codeigniter 框架能扩展数据库类实现链式方法的缓存吗

  •  
  •   heraldboy · Jan 19, 2016 · 3527 views
    This topic created in 3948 days ago, the information mentioned may be changed or developed.

    能否实现下面类似的方法:
    $row= $this->db->get_cache('key_users_favorites',60)->select('favorites')->get_where('users', array('uid'=>$uid))->row_array();
    先查找 key_users_favorites 这个 key 的数据是否存在,存在则返回一个数组。
    如果不存则继续原来的数据库查询,返回查询结果,并在这个 key 中保存数据 60 秒。

    6 replies  •  2016-03-10 16:22:42 +08:00
    chaegumi
    chaegumi
    Jan 19, 2016
    1
    想太多,直接用 cache driver 就好了
    wu1990
    wu1990
    Jan 20, 2016
    2
    laravel
    heraldboy
    heraldboy
    OP
    Jan 20, 2016
    3
    @chaegumi 不能很好的控制过期时间,感觉代码还是多了,如果像这样我就加个:->get_cache('key_users_favorites',60) 就可以缓存了。
    thenbsp
    thenbsp
    Jan 20, 2016
    4
    这个完全可以实现,不过你需要修改 CI 的 DB 类的源码, DB 类的 QueryBuilder 最终是会转为 SQL 的。
    heraldboy
    heraldboy
    OP
    Jan 20, 2016
    5
    @thenbsp 能扩展吗?最好不要动 CI
    thenbsp
    thenbsp
    Mar 10, 2016
    6
    @heraldboy 理论可以,你可以试试继承 CI 的 DB 类,我没这么试过,你测一下。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2261 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 13:37 · PVG 21:37 · LAX 05:37 · JFK 08:37
    ♥ Do have faith in what you're doing.