* Attempts to store an object to the cache.
*
* @param string $key Cache key (identifier).
- * @param mixed $data Data to store in the cache.
+ * @param string $data Data to store in the cache.
* @param integer $lifetime Data lifetime.
+ *
+ * @throws Horde_Cache_Exception
*/
public function set($key, $data, $lifetime = null)
{
+ if (!is_string($data)) {
+ throw new Horde_Cache_Exception('Data must be a string.');
+ }
$key = $this->_params['prefix'] . $key;
$lifetime = $this->_getLifetime($lifetime);
- apc_store($key . '_expire', time(), $lifetime);
- apc_store($key, $data, $lifetime);
+ if (apc_store($key . '_expire', time(), $lifetime)) {
+ apc_store($key, $data, $lifetime);
+ }
}
/**
* data becomes available for garbage
* collection. If null use the default Horde GC
* time. If 0 will not be GC'd.
+ *
+ * @throws Horde_Cache_Exception
*/
abstract public function set($key, $data, $lifetime = null);
* Attempts to store an object to the cache.
*
* @param string $key Cache key (identifier).
- * @param mixed $data Data to store in the cache.
+ * @param string $data Data to store in the cache.
* @param integer $lifetime Data lifetime.
+ *
+ * @throws Horde_Cache_Exception
*/
public function set($key, $data, $lifetime = null)
{
+ if (!is_string($data)) {
+ throw new Horde_Cache_Exception('Data must be a string.');
+ }
$key = $this->_params['prefix'] . $key;
$lifetime = $this->_getLifetime($lifetime);
- eaccelerator_put($key . '_expire', time(), $lifetime);
- eaccelerator_put($key, $data, $lifetime);
+ if (eaccelerator_put($key . '_expire', time(), $lifetime)) {
+ eaccelerator_put($key, $data, $lifetime);
+ }
}
/**
{
$key = $this->_params['prefix'] . $key;
$this->_setExpire($key, $lifetime);
- return (eaccelerator_get($key) === false) ? false : true;
+ return eaccelerator_get($key) !== false;
}
/**
* Attempts to store data to the filesystem.
*
* @param string $key Cache key.
- * @param mixed $data Data to store in the cache. (MUST BE A STRING)
+ * @param string $data Data to store in the cache.
* @param integer $lifetime Data lifetime.
+ *
+ * @throws Horde_Cache_Exception
*/
public function set($key, $data, $lifetime = null)
{
+ if (!is_string($data)) {
+ throw new Horde_Cache_Exception('Data must be a string.');
+ }
+
$filename = $this->_keyToFile($key, true);
$tmp_file = Horde_Util::getTempFile('HordeCache', true, $this->_dir);
if (isset($this->_params['umask'])) {
}
if (file_put_contents($tmp_file, $data) === false) {
- return;
+ throw new Horde_Cache_Exception('Cannot write to cache directory ' . $this->_dir);
}
@rename($tmp_file, $filename);
* @param string $key Cache key.
* @param mixed $data Data to store in the cache.
* @param integer $lifetime Data lifetime.
+ *
+ * @throws Horde_Cache_Exception
*/
public function set($key, $data, $lifetime = null)
{
+ if (!is_string($data)) {
+ throw new Horde_Cache_Exception('Data must be a string.');
+ }
+
$key = $this->_params['prefix'] . $key;
$lifetime = $this->_getLifetime($lifetime);
* Attempts to store an object to the cache.
*
* @param string $key Cache key (identifier).
- * @param mixed $data Data to store in the cache.
+ * @param string $data Data to store in the cache.
* @param integer $lifetime Data lifetime.
+ *
+ * @throws Horde_Cache_Exception
*/
public function set($key, $data, $lifetime = null)
{
+ if (!is_string($data)) {
+ throw new Horde_Cache_Exception('Data must be a string.');
+ }
$this->_cache[$key] = $data;
}
* Attempts to store an object to the cache.
*
* @param string $key Cache key (identifier).
- * @param mixed $data Data to store in the cache.
+ * @param string $data Data to store in the cache.
* @param integer $lifetime Data lifetime.
+ *
+ * @throws Horde_Cache_Exception
*/
public function set($key, $data, $lifetime = null)
{
+ if (!is_string($data)) {
+ throw new Horde_Cache_Exception('Data must be a string.');
+ }
}
/**
* Attempts to store an object to the cache.
*
* @param string $key Cache key (identifier).
- * @param mixed $data Data to store in the cache.
+ * @param string $data Data to store in the cache.
* @param integer $lifetime Data lifetime.
+ *
+ * @throws Horde_Cache_Exception
*/
public function set($key, $data, $lifetime = null)
{
+ if (!is_string($data)) {
+ throw new Horde_Cache_Exception('Data must be a string.');
+ }
$this->_sess[$key] = array(
'd' => $data,
'l' => $this->_getLifetime($lifetime)
* Attempts to store data.
*
* @param string $key Cache key.
- * @param mixed $data Data to store in the cache. (MUST BE A STRING)
+ * @param string $data Data to store in the cache.
* @param integer $lifetime Maximum data life span or 0 for a
* non-expiring object.
+ *
+ * @throws Horde_Cache_Exception
*/
public function set($key, $data, $lifetime = null)
{
+ if (!is_string($data)) {
+ throw new Horde_Cache_Exception('Data must be a string.');
+ }
+
$okey = $key;
$key = hash('md5', $key);
try {
$this->_db->insert($query, $values);
- } catch (Horde_Db_Exception $e) {}
+ } catch (Horde_Db_Exception $e) {
+ throw new Horde_Cache_Exception($e);
+ }
}
/**
* Attempts to store an object in the cache.
*
* @param string $key Object ID used as the caching key.
- * @param mixed $data Data to store in the cache.
+ * @param string $data Data to store in the cache.
* @param integer $lifetime Object lifetime - i.e. the time before the
* data becomes available for garbage
* collection. If null use the default Horde GC
* time. If 0 will not be GC'd.
+ *
+ * @throws Horde_Cache_Exception
*/
public function set($key, $data, $lifetime = null)
{
+ if (!is_string($data)) {
+ throw new Horde_Cache_Exception('Data must be a string.');
+ }
+
/* Do writes in *reverse* order - it is OK if a write to one of the
* non-master backends fails. */
$master = true;
* Attempts to store an object to the cache.
*
* @param string $key Cache key (identifier).
- * @param mixed $data Data to store in the cache.
+ * @param string $data Data to store in the cache.
* @param integer $lifetime Data lifetime.
+ *
+ * @throws Horde_Cache_Exception
*/
public function set($key, $data, $lifetime = null)
{
+ if (!is_string($data)) {
+ throw new Horde_Cache_Exception('Data must be a string.');
+ }
$key = $this->_params['prefix'] . $key;
$lifetime = $this->_getLifetime($lifetime);
- xcache_set($key . '_expire', time(), $lifetime);
- xcache_set($key, $data, $lifetime);
+ if (xcache_set($key . '_expire', time(), $lifetime)) {
+ xcache_set($key, $data, $lifetime);
+ }
}
/**