Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fadb7d3

Browse files
committed
added support for XCache cache driver.
1 parent be734ec commit fadb7d3

3 files changed

Lines changed: 142 additions & 1 deletion

File tree

src/Illuminate/Cache/CacheManager.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ protected function createWincacheDriver()
6060
return $this->repository(new WinCacheStore($this->getPrefix()));
6161
}
6262

63+
/**
64+
* Create an instance of the XCache cache driver.
65+
*
66+
* @return \Illuminate\Cache\WinCacheStore
67+
*/
68+
protected function createXcacheDriver()
69+
{
70+
return $this->repository(new XCacheStore($this->getPrefix()));
71+
}
72+
6373
/**
6474
* Create an instance of the Redis cache driver.
6575
*
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php namespace Illuminate\Cache;
2+
3+
class XCacheStore implements StoreInterface {
4+
5+
/**
6+
* A string that should be prepended to keys.
7+
*
8+
* @var string
9+
*/
10+
protected $prefix;
11+
12+
/**
13+
* Create a new WinCache store.
14+
*
15+
* @param string $prefix
16+
* @return void
17+
*/
18+
public function __construct($prefix = '')
19+
{
20+
$this->prefix = $prefix;
21+
}
22+
23+
/**
24+
* Retrieve an item from the cache by key.
25+
*
26+
* @param string $key
27+
* @return mixed
28+
*/
29+
public function get($key)
30+
{
31+
$value = xcache_get($this->prefix.$key);
32+
33+
if (isset($value))
34+
{
35+
return $value;
36+
}
37+
}
38+
39+
/**
40+
* Store an item in the cache for a given number of minutes.
41+
*
42+
* @param string $key
43+
* @param mixed $value
44+
* @param int $minutes
45+
* @return void
46+
*/
47+
public function put($key, $value, $minutes)
48+
{
49+
xcache_set($this->prefix.$key, $value, $minutes * 60);
50+
}
51+
52+
/**
53+
* Increment the value of an item in the cache.
54+
*
55+
* @param string $key
56+
* @param mixed $value
57+
* @return void
58+
*/
59+
public function increment($key, $value = 1)
60+
{
61+
return xcache_inc($this->prefix.$key, $value);
62+
}
63+
64+
/**
65+
* Increment the value of an item in the cache.
66+
*
67+
* @param string $key
68+
* @param mixed $value
69+
* @return void
70+
*/
71+
public function decrement($key, $value = 1)
72+
{
73+
return xcache_dec($this->prefix.$key, $value);
74+
}
75+
76+
/**
77+
* Store an item in the cache indefinitely.
78+
*
79+
* @param string $key
80+
* @param mixed $value
81+
* @return void
82+
*/
83+
public function forever($key, $value)
84+
{
85+
return $this->put($key, $value, 0);
86+
}
87+
88+
/**
89+
* Remove an item from the cache.
90+
*
91+
* @param string $key
92+
* @return void
93+
*/
94+
public function forget($key)
95+
{
96+
xcache_unset($this->prefix.$key);
97+
}
98+
99+
/**
100+
* Remove all items from the cache.
101+
*
102+
* @return void
103+
*/
104+
public function flush()
105+
{
106+
xcache_clear_cache(XC_TYPE_VAR);
107+
}
108+
109+
/**
110+
* Begin executing a new section operation.
111+
*
112+
* @param string $name
113+
* @return \Illuminate\Cache\Section
114+
*/
115+
public function section($name)
116+
{
117+
return new Section($this, $name);
118+
}
119+
120+
/**
121+
* Get the cache key prefix.
122+
*
123+
* @return string
124+
*/
125+
public function getPrefix()
126+
{
127+
return $this->prefix;
128+
}
129+
130+
}

src/Illuminate/Foundation/changes.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
{"message": "Added 'dates' property to Eloquent model for convenient setting of date columns.", "backport": null},
3838
{"message": "Added 'chunk' method to query builder and Eloquent for doing work on large result sets.", "backport": null},
3939
{"message": "Facades are now mockable without an application root.", "backport": null},
40-
{"message": "Data may now be dynamically bound to views via magic methods.", "backport": null}
40+
{"message": "Data may now be dynamically bound to views via magic methods.", "backport": null},
41+
{"message": "Added support for XCache cache driver.", "backport": null}
4142
]
4243
}

0 commit comments

Comments
 (0)