我想知道是否有任何方法可以更新缓存TTL自上次访问以来?
目前,我有一种方法可以通过API调用登录到adobe connect,API会话从最后一次调用起4天内有效。但我的缓存驱动程序仅在添加后的4天内将会话保留在缓存中。但我想保留它4天,因为它最后一次访问!
有没有办法更新Cache TTL?我确信忘记并重新插入密钥不是最好的做法。
/**
* Login Client Based on information that introduced in environment/config file
*
* @param Client $client
*
* @return void
*/
private function loginClient(Client $client)
{
$config = $this->app["config"]->get("adobeConnect");
$session = Cache::store($config["session-cache"]["driver"])->remember(
$config['session-cache']['key'],
$config['session-cache']['expire'],
function () use ($config, $client) {
$client->login($config["user-name"], $config["password"]);
return $client->getSession();
});
$client->setSession($session);
}发布于 2019-09-13 20:32:13
您可以侦听事件CacheHit,测试键模式,并使用新的TTL重置该键的缓存。
为此,应创建一个新的监听器并将其添加到EventServiceProvider中
protected $listen = [
'Illuminate\Cache\Events\CacheHit' => [
'App\Listeners\UpdateAdobeCache',
]
];和听众:
class UpdateAdobeCache {
public function handle(CacheHit $event)
{
if ($event->key === 'the_cache_key') { // you could also test for a match with regexp
Cache::store($config["session-cache"]["driver"])->put($event->key, $event->value, $newTTL);
}
}
}https://stackoverflow.com/questions/57831159
复制相似问题