Passed
Pull Request — master (#30)
by Mostafa
11:18
created

RefreshDebouncer::dispatch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
c 1
b 0
f 1
dl 0
loc 13
rs 10
cc 1
nc 1
nop 5
1
<?php
2
3
namespace Mostafaznv\LaraCache\Utils;
4
5
use Illuminate\Support\Facades\Cache;
6
use Illuminate\Support\Str;
7
use Mostafaznv\LaraCache\Jobs\DebounceRefresh;
8
9
10
class RefreshDebouncer
11
{
12
    public static function dispatch(string $model, string $name, string $queueConnection, string $queueName, int $wait = 5): void
13
    {
14
        $key = "laracache.debounce.$model:token";
15
16
        $token = Str::uuid()->toString();
17
        $ttl = $wait + 60;
18
19
        Cache::put($key, $token, $ttl);
20
21
        DebounceRefresh::dispatch($key, $token, $model, $name)
22
            ->onConnection($queueConnection)
23
            ->onQueue($queueName)
24
            ->delay($wait);
25
    }
26
}
27