1+ <?php
2+
3+ namespace Overtrue \LaravelWechat ;
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+ return Cache::put ($ id , $ data , $ lifeTime / 60 );
53+ }
54+
55+ /**
56+ * Deletes a cache entry.
57+ *
58+ * @param string $id The cache id.
59+ *
60+ * @return bool TRUE if the cache entry was successfully deleted, FALSE otherwise.
61+ * Deleting a non-existing entry is considered successful.
62+ */
63+ public function delete ($ id )
64+ {
65+ return Cache::forget ($ id );
66+ }
67+
68+ /**
69+ * Retrieves cached information from the data store.
70+ *
71+ * @return array|null An associative array with server's statistics if available, NULL otherwise.
72+ */
73+ public function getStats ()
74+ {
75+ return null ;
76+ }
77+ }
0 commit comments