ticket-723_with_proposal.diff

Same as previous patch, only now with the proposal. - Mark van der Velden -, 11/09/2008 10:23 am

Download (3.4 kB)

 
cache.php (working copy)
117 117

  
118 118
		if ($data = $this->driver->get($id))
119 119
		{
120
			if (substr($data, 0, 14) === '<{serialized}>')
120
			if ($this->driver->serialize === true && substr($data, 0, 14) === '<{serialized}>')
121 121
			{
122 122
				// Data has been serialized, unserialize now
123 123
				$data = unserialize(substr($data, 14));
......
172 172
		// Change slashes to colons
173 173
		$id = str_replace(array('/', '\\'), '=', $id);
174 174

  
175
		if ( ! is_string($data))
175
		if ($this->driver->serialize === true && ! is_string($data))
176 176
		{
177 177
			// Serialize all non-string data, so that types can be preserved
178 178
			$data = '<{serialized}>'.serialize($data);
......
214 214
	{
215 215
		return $this->driver->delete(FALSE, $tag);
216 216
	}
217

  
217
	
218 218
	/**
219
	 * Delete ALL cache items items.
220
	 *
221
	 * @return  boolean
219
	 * get multiple cache items
220
	 * @param	array $ids (A array with cache ids)
221
	 * @return	array
222 222
	 */
223
	public function delete_all()
223
	public function getMultiple(Array $ids) 
224 224
	{
225
		return $this->driver->delete(TRUE);
225
		$data = array();
226
		foreach ($ids as $id) 
227
		{
228
			$data[ $id ]	= $this->get($id);
229
		}
230
		
231
		return $data;
226 232
	}
233
	
234
	/**
235
	 * set multiple cache items, data format in: array(<cache id> => <data>);
236
	 *
237
	 * @param array $data
238
	 * @param array $tags
239
	 * @param integer $lifetime
240
	 * @return boolean
241
	 */
242
	public function setMultiple(Array $data, $tags = NULL, $lifetime = NULL) {
243
		foreach ($data as $id=>$cacheData) 
244
		{
245
			if (!$this->set($id, $cacheData, $tags, $lifetime))
246
			{
247
				return FALSE;
248
			}
249
		}
227 250

  
251
		return TRUE;
252
	}
253

  
228 254
} // End Cache
cache/driver.php (working copy)
10 10
 * @license    http://kohanaphp.com/license.html
11 11
 */
12 12
abstract class Cache_Driver {
13
	
14
	/**
15
	 * A driver specific overridable serialize setting,
16
	 * false means the driver takes care of serializing.
17
	 * 
18
	 * @var boolean
19
	 */
20
	public $serialize	= true;
13 21

  
14 22
	/**
15 23
	 * Set a cache item.
......
36 44
	 * Deletes all expired cache items.
37 45
	 */
38 46
	abstract public function delete_expired();
47
	
48
	/**
49
	 * get multiple cache items
50
	 * @param	array $ids (A array with cache ids)
51
	 * @return	array
52
	 */
53
	public function getMultiple(Array $ids) 
54
	{
55
		$data = array();
56
		foreach ($ids as $id) 
57
		{
58
			$data[ $id ]	= $this->get($id);
59
		}
60
		
61
		return $data;
62
	}
63
	
64
	/**
65
	 * set multiple cache items, data format in: array(<cache id> => <data>);
66
	 *
67
	 * @param array $data
68
	 * @param array $tags
69
	 * @param integer $lifetime
70
	 * @return boolean
71
	 */
72
	public function setMultiple(Array $data, $tags, $lifetime) 
73
	{
74
		foreach ($data as $id=>$cacheData) 
75
		{
76
			if (!$this->set($id, $cacheData, $tags, $lifetime)) 
77
			{
78
				return FALSE;
79
			}
80
		}
39 81

  
82
		return TRUE;
83
	}
84

  
40 85
} // End Cache Driver
cache/driver/memcache.php (working copy)
14 14
	// Cache backend object and flags
15 15
	protected $backend;
16 16
	protected $flags;
17
	
18
	/**
19
	 * Disable serializing in our cache driver
20
	 * 
21
	 * @var boolean
22
	 */
23
	public	$serialize	= false;
17 24

  
18 25
	public function __construct()
19 26
	{