heraldboy
V2EX  ›  PHP

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

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