Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Console\Scheduling;
4
 
5
use Illuminate\Contracts\Cache\Factory as Cache;
621 lars 6
use Illuminate\Contracts\Cache\LockProvider;
148 lars 7
 
8
class CacheEventMutex implements EventMutex, CacheAware
9
{
10
    /**
11
     * The cache repository implementation.
12
     *
13
     * @var \Illuminate\Contracts\Cache\Factory
14
     */
15
    public $cache;
16
 
17
    /**
18
     * The cache store that should be used.
19
     *
20
     * @var string|null
21
     */
22
    public $store;
23
 
24
    /**
25
     * Create a new overlapping strategy.
26
     *
27
     * @param  \Illuminate\Contracts\Cache\Factory  $cache
28
     * @return void
29
     */
30
    public function __construct(Cache $cache)
31
    {
32
        $this->cache = $cache;
33
    }
34
 
35
    /**
36
     * Attempt to obtain an event mutex for the given event.
37
     *
38
     * @param  \Illuminate\Console\Scheduling\Event  $event
39
     * @return bool
40
     */
41
    public function create(Event $event)
42
    {
621 lars 43
        if ($this->cache->store($this->store)->getStore() instanceof LockProvider) {
44
            return $this->cache->store($this->store)->getStore()
45
                ->lock($event->mutexName(), $event->expiresAt * 60)
46
                ->acquire();
47
        }
48
 
148 lars 49
        return $this->cache->store($this->store)->add(
50
            $event->mutexName(), true, $event->expiresAt * 60
51
        );
52
    }
53
 
54
    /**
55
     * Determine if an event mutex exists for the given event.
56
     *
57
     * @param  \Illuminate\Console\Scheduling\Event  $event
58
     * @return bool
59
     */
60
    public function exists(Event $event)
61
    {
621 lars 62
        if ($this->cache->store($this->store)->getStore() instanceof LockProvider) {
63
            return ! $this->cache->store($this->store)->getStore()
64
                ->lock($event->mutexName(), $event->expiresAt * 60)
65
                ->get(fn () => true);
66
        }
67
 
148 lars 68
        return $this->cache->store($this->store)->has($event->mutexName());
69
    }
70
 
71
    /**
72
     * Clear the event mutex for the given event.
73
     *
74
     * @param  \Illuminate\Console\Scheduling\Event  $event
75
     * @return void
76
     */
77
    public function forget(Event $event)
78
    {
621 lars 79
        if ($this->cache->store($this->store)->getStore() instanceof LockProvider) {
80
            $this->cache->store($this->store)->getStore()
81
                ->lock($event->mutexName(), $event->expiresAt * 60)
82
                ->forceRelease();
83
 
84
            return;
85
        }
86
 
148 lars 87
        $this->cache->store($this->store)->forget($event->mutexName());
88
    }
89
 
90
    /**
91
     * Specify the cache store that should be used.
92
     *
93
     * @param  string  $store
94
     * @return $this
95
     */
96
    public function useStore($store)
97
    {
98
        $this->store = $store;
99
 
100
        return $this;
101
    }
102
}