我正在尝试使用节点缓存的“过期”事件在缓存键值对的 TTL 结束时提取最新数据。我的理解是,当缓存过期时应该立即调用它,但我认为直到检查周期结束并且缓存清理过期值之前它不会被调用。是这样还是我做错了什么?
小智 6
默认情况下,节点缓存不会定期检查过期的密钥,因此只有在访问密钥时才会触发过期事件。checkperiod您可以通过在创建节点缓存时设置选项来更改此行为。
checkperiod: (default: 600) The period in seconds, as a number, used for the automatic delete check interval. 0 = no periodic check.
Run Code Online (Sandbox Code Playgroud)
const NodeCache = require( "node-cache" );
const myCache = new NodeCache({ checkperiod: 120 }); // will check every 120 seconds
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4838 次 |
| 最近记录: |