Projekt

Obecné

Profil

Stáhnout (1.85 KB) Statistiky
| Větev: | Revize:
1 cb15593b Cajova-Houba
<?php
2
3
namespace Illuminate\Cache;
4
5
class ApcWrapper
6
{
7
    /**
8
     * Indicates if APCu is supported.
9
     *
10
     * @var bool
11
     */
12
    protected $apcu = false;
13
14
    /**
15
     * Create a new APC wrapper instance.
16
     *
17
     * @return void
18
     */
19
    public function __construct()
20
    {
21
        $this->apcu = function_exists('apcu_fetch');
22
    }
23
24
    /**
25
     * Get an item from the cache.
26
     *
27
     * @param  string  $key
28
     * @return mixed
29
     */
30
    public function get($key)
31
    {
32
        return $this->apcu ? apcu_fetch($key) : apc_fetch($key);
33
    }
34
35
    /**
36
     * Store an item in the cache.
37
     *
38
     * @param  string  $key
39
     * @param  mixed   $value
40
     * @param  int     $seconds
41
     * @return array|bool
42
     */
43
    public function put($key, $value, $seconds)
44
    {
45
        return $this->apcu ? apcu_store($key, $value, $seconds) : apc_store($key, $value, $seconds);
46
    }
47
48
    /**
49
     * Increment the value of an item in the cache.
50
     *
51
     * @param  string  $key
52
     * @param  mixed   $value
53
     * @return int|bool
54
     */
55
    public function increment($key, $value)
56
    {
57
        return $this->apcu ? apcu_inc($key, $value) : apc_inc($key, $value);
58
    }
59
60
    /**
61
     * Decrement the value of an item in the cache.
62
     *
63
     * @param  string  $key
64
     * @param  mixed   $value
65
     * @return int|bool
66
     */
67
    public function decrement($key, $value)
68
    {
69
        return $this->apcu ? apcu_dec($key, $value) : apc_dec($key, $value);
70
    }
71
72
    /**
73
     * Remove an item from the cache.
74
     *
75
     * @param  string  $key
76
     * @return bool
77
     */
78
    public function delete($key)
79
    {
80
        return $this->apcu ? apcu_delete($key) : apc_delete($key);
81
    }
82
83
    /**
84
     * Remove all items from the cache.
85
     *
86
     * @return void
87
     */
88
    public function flush()
89
    {
90
        $this->apcu ? apcu_clear_cache() : apc_clear_cache('user');
91
    }
92
}