Webklex / laravel-imap

Laravel IMAP is an easy way to integrate both the native php-imap module and an extended custom imap protocol into your Laravel app.
https://www.php-imap.com
MIT License
641 stars 182 forks source link

cache connection #451

Closed olrtan closed 2 years ago

olrtan commented 2 years ago

Hi , I want to ask you: can i make the connection cache?

$client= Cache::remember('client', 100000 * 60, function () {
        return $client->connect();
    });

if yes how ? thanks you

Webklex commented 2 years ago

Hi @olrtan , that's a good question. I've never tried it. You could try something like this:

$client= Cache::remember('client', 100000 * 60, function () {
    $client = Webklex\IMAP\Facades\Client::account('default');
    $client->connect();
    return $client;
});

..but I don't know if the resource / connection itself is managed properly. I also don't know if it is a good idea in general - something has to manage the open connection - does it get dropped by the sever after a certain time? Will it reconnect by itself if required? Is the session still valid after x minutes / days?

Best regards,