Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Cache;
4
 
5
class MemcachedLock extends Lock
6
{
7
    /**
8
     * The Memcached instance.
9
     *
10
     * @var \Memcached
11
     */
12
    protected $memcached;
13
 
14
    /**
15
     * Create a new lock instance.
16
     *
17
     * @param  \Memcached  $memcached
18
     * @param  string  $name
19
     * @param  int  $seconds
20
     * @param  string|null  $owner
21
     * @return void
22
     */
23
    public function __construct($memcached, $name, $seconds, $owner = null)
24
    {
25
        parent::__construct($name, $seconds, $owner);
26
 
27
        $this->memcached = $memcached;
28
    }
29
 
30
    /**
31
     * Attempt to acquire the lock.
32
     *
33
     * @return bool
34
     */
35
    public function acquire()
36
    {
37
        return $this->memcached->add(
38
            $this->name, $this->owner, $this->seconds
39
        );
40
    }
41
 
42
    /**
43
     * Release the lock.
44
     *
45
     * @return bool
46
     */
47
    public function release()
48
    {
49
        if ($this->isOwnedByCurrentProcess()) {
50
            return $this->memcached->delete($this->name);
51
        }
52
 
53
        return false;
54
    }
55
 
56
    /**
57
     * Releases this lock in disregard of ownership.
58
     *
59
     * @return void
60
     */
61
    public function forceRelease()
62
    {
63
        $this->memcached->delete($this->name);
64
    }
65
 
66
    /**
67
     * Returns the owner value written into the driver for this lock.
68
     *
69
     * @return mixed
70
     */
71
    protected function getCurrentOwner()
72
    {
73
        return $this->memcached->get($this->name);
74
    }
75
}