Passed
Pull Request — master (#30)
by Mostafa
02:28
created

RefreshDebouncer   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 1
eloc 9
c 1
b 0
f 1
dl 0
loc 15
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A dispatch() 0 13 1
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