|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Freyo\LaravelEntWechat; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Cache\Cache as CacheInterface; |
|
6
|
|
|
use Illuminate\Support\Facades\Cache; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Cache bridge for laravel. |
|
10
|
|
|
*/ |
|
11
|
|
|
class CacheBridge implements CacheInterface |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Fetches an entry from the cache. |
|
15
|
|
|
* |
|
16
|
|
|
* @param string $id The id of the cache entry to fetch. |
|
17
|
|
|
* |
|
18
|
|
|
* @return mixed The cached data or FALSE, if no cache entry exists for the given id. |
|
19
|
|
|
*/ |
|
20
|
|
|
public function fetch($id) |
|
21
|
|
|
{ |
|
22
|
|
|
return Cache::get($id); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Tests if an entry exists in the cache. |
|
27
|
|
|
* |
|
28
|
|
|
* @param string $id The cache id of the entry to check for. |
|
29
|
|
|
* |
|
30
|
|
|
* @return bool TRUE if a cache entry exists for the given cache id, FALSE otherwise. |
|
31
|
|
|
*/ |
|
32
|
|
|
public function contains($id) |
|
33
|
|
|
{ |
|
34
|
|
|
return Cache::has($id); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Puts data into the cache. |
|
39
|
|
|
* |
|
40
|
|
|
* If a cache entry with the given id already exists, its data will be replaced. |
|
41
|
|
|
* |
|
42
|
|
|
* @param string $id The cache id. |
|
43
|
|
|
* @param mixed $data The cache entry/data. |
|
44
|
|
|
* @param int $lifeTime The lifetime in number of seconds for this cache entry. |
|
45
|
|
|
* If zero (the default), the entry never expires (although it may be deleted from the cache |
|
46
|
|
|
* to make place for other entries). |
|
47
|
|
|
* |
|
48
|
|
|
* @return bool TRUE if the entry was successfully stored in the cache, FALSE otherwise. |
|
49
|
|
|
*/ |
|
50
|
|
|
public function save($id, $data, $lifeTime = 0) |
|
51
|
|
|
{ |
|
52
|
|
|
if ($lifeTime == 0) { |
|
53
|
|
|
return Cache::forever($id, $data); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return Cache::put($id, $data, $lifeTime / 60); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Deletes a cache entry. |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $id The cache id. |
|
63
|
|
|
* |
|
64
|
|
|
* @return bool TRUE if the cache entry was successfully deleted, FALSE otherwise. |
|
65
|
|
|
* Deleting a non-existing entry is considered successful. |
|
66
|
|
|
*/ |
|
67
|
|
|
public function delete($id) |
|
68
|
|
|
{ |
|
69
|
|
|
return Cache::forget($id); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Retrieves cached information from the data store. |
|
74
|
|
|
* |
|
75
|
|
|
* @return array|null An associative array with server's statistics if available, NULL otherwise. |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getStats() |
|
78
|
|
|
{ |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|