Skip to content
欢迎扫码关注公众号

ThinkPHP 延迟更新

当需要频繁更新一些统计字段的时候,为了减少数据库压力,ThinkPHP 提供了延迟更新的功能。

php
$coin = D('test_coin');
$coin->where(1)->setLazyInc('coin', 100, 10);
return $coin->find(1);

coin 值加 100,10s 后更新到 DB。

同理 setLazyDec 方法是减法的延迟更新。

注意点

  1. 关于实际更新到的 DB 的时间点,跟预想是有差距的。实际的更新时间并不是第一次该语句执行的 10s 后,而是 10s 后该语句再次被调用时(即,10s 后若该语句再也没被调用过,则永远不会被更新到 DB)。

  2. 由于用的 3.2.2 版本的 ThinkPHP,Model 需要 继承 AdvModel,否则没有该方法。

Page Layout Max Width

Adjust the exact value of the page width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the page layout
A ranged slider for user to choose and customize their desired width of the maximum width of the page layout can go.

Content Layout Max Width

Adjust the exact value of the document content width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the content layout
A ranged slider for user to choose and customize their desired width of the maximum width of the content layout can go.