Skip to content

Commit

Permalink
Add Memory driver
Browse files Browse the repository at this point in the history
Deprecate Mock driver.
  • Loading branch information
slusarz committed Apr 8, 2014
1 parent 6891c9d commit 486fce8
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 59 deletions.
75 changes: 75 additions & 0 deletions framework/Cache/lib/Horde/Cache/Storage/Memory.php
@@ -0,0 +1,75 @@
<?php
/**
* Copyright 2010-2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @copyright 2010-2014 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Cache
* @package Cache
*/

/**
* Cache storage in PHP memory.
* It persists only during a script run and ignores the object lifetime
* because of that.
*
* @author Gunnar Wrobel <wrobel@pardus.de>
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2010-2014 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Cache
* @package Cache
* @since 2.5.0
*/
class Horde_Cache_Storage_Memory extends Horde_Cache_Storage_Base
{
/**
* Storage for this cache.
*
* @var array
*/
private $_cache = array();

/**
*/
public function get($key, $lifetime = 0)
{
return isset($this->_cache[$key])
? $this->_cache[$key]
: false;
}

/**
*/
public function set($key, $data, $lifetime = 0)
{
$this->_cache[$key] = $data;
}

/**
*/
public function exists($key, $lifetime = 0)
{
return isset($this->_cache[$key]);
}

/**
*/
public function expire($key)
{
unset($this->_cache[$key]);
}

/**
*/
public function clear()
{
$this->_cache = array();
}

}
2 changes: 1 addition & 1 deletion framework/Cache/lib/Horde/Cache/Storage/Memoryoverlay.php
Expand Up @@ -19,7 +19,7 @@
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2013-2014 Horde LLC
* @deprecated Use Mock driver as initial backen in stack driver instead.
* @deprecated Use Memory driver as first backend in stack driver instead.
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Cache
* @package Cache
Expand Down
54 changes: 2 additions & 52 deletions framework/Cache/lib/Horde/Cache/Storage/Mock.php
Expand Up @@ -20,61 +20,11 @@
* @author Gunnar Wrobel <wrobel@pardus.de>
* @category Horde
* @copyright 2010-2014 Horde LLC
* @deprecated Use Memory driver instead.
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Cache
* @package Cache
*/
class Horde_Cache_Storage_Mock extends Horde_Cache_Storage_Base
class Horde_Cache_Storage_Mock extends Horde_Cache_Storage_Memory
{
/**
* The storage location for this cache.
*
* @var array
*/
private $_cache = array();

/**
*/
public function __sleep()
{
throw new BadMethodCallException('Cannot serialize this object.');
}

/**
*/
public function get($key, $lifetime = 0)
{
return isset($this->_cache[$key])
? $this->_cache[$key]
: false;
}

/**
*/
public function set($key, $data, $lifetime = 0)
{
$this->_cache[$key] = $data;
}

/**
*/
public function exists($key, $lifetime = 0)
{
return isset($this->_cache[$key]);
}

/**
*/
public function expire($key)
{
unset($this->_cache[$key]);
}

/**
*/
public function clear()
{
$this->_cache = array();
}

}
14 changes: 8 additions & 6 deletions framework/Cache/package.xml
Expand Up @@ -16,10 +16,10 @@
<email>slusarz@horde.org</email>
<active>yes</active>
</lead>
<date>2014-04-07</date>
<date>2014-04-08</date>
<version>
<release>2.4.3</release>
<api>2.4.0</api>
<release>2.5.0</release>
<api>2.5.0</api>
</version>
<stability>
<release>stable</release>
Expand Down Expand Up @@ -48,6 +48,7 @@
<file name="File.php" role="php" />
<file name="Hashtable.php" role="php" />
<file name="Memcache.php" role="php" />
<file name="Memory.php" role="php" />
<file name="Memoryoverlay.php" role="php" />
<file name="Mock.php" role="php" />
<file name="Mongo.php" role="php" />
Expand Down Expand Up @@ -166,6 +167,7 @@
<install as="Horde/Cache/Storage/File.php" name="lib/Horde/Cache/Storage/File.php" />
<install as="Horde/Cache/Storage/Hashtable.php" name="lib/Horde/Cache/Storage/Hashtable.php" />
<install as="Horde/Cache/Storage/Memcache.php" name="lib/Horde/Cache/Storage/Memcache.php" />
<install as="Horde/Cache/Storage/Memory.php" name="lib/Horde/Cache/Storage/Memory.php" />
<install as="Horde/Cache/Storage/Memoryoverlay.php" name="lib/Horde/Cache/Storage/Memoryoverlay.php" />
<install as="Horde/Cache/Storage/Mock.php" name="lib/Horde/Cache/Storage/Mock.php" />
<install as="Horde/Cache/Storage/Mongo.php" name="lib/Horde/Cache/Storage/Mongo.php" />
Expand Down Expand Up @@ -560,12 +562,12 @@ Initial packaging.
</release>
<release>
<version>
<release>2.4.3</release>
<api>2.4.0</api></version>
<release>2.5.0</release>
<api>2.5.0</api></version>
<stability>
<release>stable</release>
<api>stable</api></stability>
<date>2014-04-07</date>
<date>2014-04-08</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
Expand Down

0 comments on commit 486fce8

Please sign in to comment.