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 ApcStore extends TaggableStore
6
{
7
    use RetrievesMultipleKeys;
8
 
9
    /**
10
     * The APC wrapper instance.
11
     *
12
     * @var \Illuminate\Cache\ApcWrapper
13
     */
14
    protected $apc;
15
 
16
    /**
17
     * A string that should be prepended to keys.
18
     *
19
     * @var string
20
     */
21
    protected $prefix;
22
 
23
    /**
24
     * Create a new APC store.
25
     *
26
     * @param  \Illuminate\Cache\ApcWrapper  $apc
27
     * @param  string  $prefix
28
     * @return void
29
     */
30
    public function __construct(ApcWrapper $apc, $prefix = '')
31
    {
32
        $this->apc = $apc;
33
        $this->prefix = $prefix;
34
    }
35
 
36
    /**
37
     * Retrieve an item from the cache by key.
38
     *
39
     * @param  string|array  $key
40
     * @return mixed
41
     */
42
    public function get($key)
43
    {
44
        $value = $this->apc->get($this->prefix.$key);
45
 
46
        if ($value !== false) {
47
            return $value;
48
        }
49
    }
50
 
51
    /**
52
     * Store an item in the cache for a given number of seconds.
53
     *
54
     * @param  string  $key
55
     * @param  mixed  $value
56
     * @param  int  $seconds
57
     * @return bool
58
     */
59
    public function put($key, $value, $seconds)
60
    {
61
        return $this->apc->put($this->prefix.$key, $value, $seconds);
62
    }
63
 
64
    /**
65
     * Increment the value of an item in the cache.
66
     *
67
     * @param  string  $key
68
     * @param  mixed  $value
69
     * @return int|bool
70
     */
71
    public function increment($key, $value = 1)
72
    {
73
        return $this->apc->increment($this->prefix.$key, $value);
74
    }
75
 
76
    /**
77
     * Decrement the value of an item in the cache.
78
     *
79
     * @param  string  $key
80
     * @param  mixed  $value
81
     * @return int|bool
82
     */
83
    public function decrement($key, $value = 1)
84
    {
85
        return $this->apc->decrement($this->prefix.$key, $value);
86
    }
87
 
88
    /**
89
     * Store an item in the cache indefinitely.
90
     *
91
     * @param  string  $key
92
     * @param  mixed  $value
93
     * @return bool
94
     */
95
    public function forever($key, $value)
96
    {
97
        return $this->put($key, $value, 0);
98
    }
99
 
100
    /**
101
     * Remove an item from the cache.
102
     *
103
     * @param  string  $key
104
     * @return bool
105
     */
106
    public function forget($key)
107
    {
108
        return $this->apc->delete($this->prefix.$key);
109
    }
110
 
111
    /**
112
     * Remove all items from the cache.
113
     *
114
     * @return bool
115
     */
116
    public function flush()
117
    {
118
        return $this->apc->flush();
119
    }
120
 
121
    /**
122
     * Get the cache key prefix.
123
     *
124
     * @return string
125
     */
126
    public function getPrefix()
127
    {
128
        return $this->prefix;
129
    }
130
}