Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | 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;
6
 
7
class CacheEventMutex implements EventMutex, CacheAware
8
{
9
    /**
10
     * The cache repository implementation.
11
     *
12
     * @var \Illuminate\Contracts\Cache\Factory
13
     */
14
    public $cache;
15
 
16
    /**
17
     * The cache store that should be used.
18
     *
19
     * @var string|null
20
     */
21
    public $store;
22
 
23
    /**
24
     * Create a new overlapping strategy.
25
     *
26
     * @param  \Illuminate\Contracts\Cache\Factory  $cache
27
     * @return void
28
     */
29
    public function __construct(Cache $cache)
30
    {
31
        $this->cache = $cache;
32
    }
33
 
34
    /**
35
     * Attempt to obtain an event mutex for the given event.
36
     *
37
     * @param  \Illuminate\Console\Scheduling\Event  $event
38
     * @return bool
39
     */
40
    public function create(Event $event)
41
    {
42
        return $this->cache->store($this->store)->add(
43
            $event->mutexName(), true, $event->expiresAt * 60
44
        );
45
    }
46
 
47
    /**
48
     * Determine if an event mutex exists for the given event.
49
     *
50
     * @param  \Illuminate\Console\Scheduling\Event  $event
51
     * @return bool
52
     */
53
    public function exists(Event $event)
54
    {
55
        return $this->cache->store($this->store)->has($event->mutexName());
56
    }
57
 
58
    /**
59
     * Clear the event mutex for the given event.
60
     *
61
     * @param  \Illuminate\Console\Scheduling\Event  $event
62
     * @return void
63
     */
64
    public function forget(Event $event)
65
    {
66
        $this->cache->store($this->store)->forget($event->mutexName());
67
    }
68
 
69
    /**
70
     * Specify the cache store that should be used.
71
     *
72
     * @param  string  $store
73
     * @return $this
74
     */
75
    public function useStore($store)
76
    {
77
        $this->store = $store;
78
 
79
        return $this;
80
    }
81
}