Author: as
Date: Fri Oct 5 14:41:33 2007
New Revision: 6374
Log:
- Fixed issue #11181: A physical location is not required anymore for pure
memory backends.
Modified:
trunk/Cache/ChangeLog
trunk/Cache/docs/tutorial.txt
trunk/Cache/docs/tutorial_apc_plain.php
trunk/Cache/docs/tutorial_memcache_plain.php
trunk/Cache/src/manager.php
trunk/Cache/src/storage.php
trunk/Cache/src/storage/apc.php
trunk/Cache/src/storage/apc/apc_array.php
trunk/Cache/src/storage/memcache.php
trunk/Cache/src/storage/memory.php
trunk/Cache/tests/manager_test.php
trunk/Cache/tests/storage_apc_array_test.php
trunk/Cache/tests/storage_apc_plain_test.php
trunk/Cache/tests/storage_memcache_plain_test.php
Modified: trunk/Cache/ChangeLog
==============================================================================
--- trunk/Cache/ChangeLog [iso-8859-1] (original)
+++ trunk/Cache/ChangeLog [iso-8859-1] Fri Oct 5 14:41:33 2007
@@ -6,6 +6,8 @@
- Fixed issue #11064: Marked search() as protected in ezcCacheStorageFile.
- Implemented feature request #11049: Added APC and Memcache backends for
caching. Based on a patch from Grady Kuhnline.
+- Fixed issue #11181: A physical location is not required anymore for memory
+ backends.
1.2 - Monday 02 July 2007
Modified: trunk/Cache/docs/tutorial.txt
==============================================================================
--- trunk/Cache/docs/tutorial.txt [iso-8859-1] (original)
+++ trunk/Cache/docs/tutorial.txt [iso-8859-1] Fri Oct 5 14:41:33 2007
@@ -223,7 +223,8 @@
The following example shows how to create and use a plain APC storage. It is
the same as the simple example above, but using the ezcCacheStorageApcPlain
-class instead of ezcCacheStorageFilePlain.
+class instead of ezcCacheStorageFilePlain. The second parameter of the
+createCache() method is null, because an existing path is not needed.
.. include:: tutorial_apc_plain.php
:literal:
@@ -231,7 +232,8 @@
The following example shows how to create and use an APC array storage. It is
the same as the second example above, but using the ezcCacheStorageFileApcArray
-class instead of ezcCacheStorageFileArray.
+class instead of ezcCacheStorageFileArray. The second parameter of the
+createCache() method must be an existing writeable path.
.. include:: tutorial_apc_array.php
:literal:
@@ -259,7 +261,8 @@
The following example shows how to create and use a plain Memcache storage. It
is the same as the simple example above, but using the
ezcCacheStorageMemcachePlain class instead of ezcCacheStorageFilePlain, and
-setting the required options for the storage.
+setting the required options for the storage. The second parameter of the
+createCache() method is null, because an existing path is not needed.
.. include:: tutorial_memcache_plain.php
:literal:
Modified: trunk/Cache/docs/tutorial_apc_plain.php
==============================================================================
--- trunk/Cache/docs/tutorial_apc_plain.php [iso-8859-1] (original)
+++ trunk/Cache/docs/tutorial_apc_plain.php [iso-8859-1] Fri Oct 5 14:41:33
2007
@@ -6,7 +6,7 @@
'ttl' => 30,
);
-ezcCacheManager::createCache( 'simple', '/tmp/cache/plain',
'ezcCacheStorageApcPlain', $options );
+ezcCacheManager::createCache( 'simple', null, 'ezcCacheStorageApcPlain',
$options );
$myId = 'unique_id_1';
$mySecondId = 'id_2';
Modified: trunk/Cache/docs/tutorial_memcache_plain.php
==============================================================================
--- trunk/Cache/docs/tutorial_memcache_plain.php [iso-8859-1] (original)
+++ trunk/Cache/docs/tutorial_memcache_plain.php [iso-8859-1] Fri Oct 5
14:41:33 2007
@@ -8,7 +8,7 @@
'port' => 11211
);
-ezcCacheManager::createCache( 'simple', '/tmp/cache/plain',
'ezcCacheStorageMemcachePlain', $options );
+ezcCacheManager::createCache( 'simple', null, 'ezcCacheStorageMemcachePlain',
$options );
$myId = 'unique_id_1';
$mySecondId = 'id_2';
Modified: trunk/Cache/src/manager.php
==============================================================================
--- trunk/Cache/src/manager.php [iso-8859-1] (original)
+++ trunk/Cache/src/manager.php [iso-8859-1] Fri Oct 5 14:41:33 2007
@@ -153,7 +153,10 @@
* The $location parameter depends on the kind of [EMAIL PROTECTED]
ezcCacheStorage}
* used for the cache you create. Usually this is a directory on your
* file system, but may also be e.g. a data source name, if you cache in
- * a database or similar.
+ * a database or similar. For memory-based storage ([EMAIL PROTECTED]
ezcCacheStorageApcPlain}
+ * or [EMAIL PROTECTED] ezcCacheStorageMemcachePlain}) it is null, but for
+ * memory/file hybrid storage ([EMAIL PROTECTED]
ezcCacheStorageFileApcArray}) it should
+ * be an existing writeable path.
*
* The $options array consists of several standard attributes and can
* additionally contain options defined by the [EMAIL PROTECTED]
ezcCacheStorage}
@@ -166,7 +169,10 @@
* </code>
*
* @param string $id ID of the cache to create.
- * @param string $location Location to create the cache in.
+ * @param string $location Location to create the cache in.
Null for
+ * memory-based storage and an
existing
+ * writeable path for file or
memory/file
+ * storage.
* @param string $storageClass Subclass of [EMAIL PROTECTED]
ezcCacheStorage}.
* @param array(string=>string) $options Options for the cache.
* @return void
@@ -187,30 +193,35 @@
* If the given storage class does not exist or is no subclass of
* ezcCacheStorage.
*/
- public static function createCache( $id, $location, $storageClass,
$options = array() )
+ public static function createCache( $id, $location = null, $storageClass,
$options = array() )
{
- // Sanity check existance.
- if ( !file_exists( $location ) || !is_dir( $location ) )
+ if ( $location !== null )
{
- throw new ezcBaseFileNotFoundException( $location, 'cache
location', 'Does not exists or is no directory.' );
+ // Sanity check existance.
+ if ( !file_exists( $location ) || !is_dir( $location ) )
+ {
+ throw new ezcBaseFileNotFoundException( $location, 'cache
location', 'Does not exists or is no directory.' );
+ }
+ if ( !is_readable( $location ) )
+ {
+ throw new ezcBaseFilePermissionException( $location,
ezcBaseFileException::READ, 'Cache location is not readable.' );
+ }
+ if ( !is_writeable( $location ) )
+ {
+ throw new ezcBaseFilePermissionException( $location,
ezcBaseFileException::WRITE, 'Cache location is not writeable.' );
+ }
+ $location = realpath( $location );
+
+ // Sanity check double taken locations.
+ foreach ( self::$configurations as $confId => $config )
+ {
+ if ( $config['location'] == $location )
+ {
+ throw new ezcCacheUsedLocationException( $location,
$confId );
+ }
+ }
}
- if ( !is_readable( $location ) )
- {
- throw new ezcBaseFilePermissionException( $location,
ezcBaseFileException::READ, 'Cache location is not readable.' );
- }
- if ( !is_writeable( $location ) )
- {
- throw new ezcBaseFilePermissionException( $location,
ezcBaseFileException::WRITE, 'Cache location is not writeable.' );
- }
- $location = realpath( $location );
- // Sanity check double taken locations.
- foreach ( self::$configurations as $confId => $config )
- {
- if ( $config['location'] == $location )
- {
- throw new ezcCacheUsedLocationException( $location, $confId );
- }
- }
+
// Sanity check storage class.
if ( !ezcBaseFeatures::classExists( $storageClass ) ||
!is_subclass_of( $storageClass, 'ezcCacheStorage' ) )
{
Modified: trunk/Cache/src/storage.php
==============================================================================
--- trunk/Cache/src/storage.php [iso-8859-1] (original)
+++ trunk/Cache/src/storage.php [iso-8859-1] Fri Oct 5 14:41:33 2007
@@ -61,14 +61,19 @@
* Creates a new cache storage in the given location.
* Creates a new cache storage for a given location. The location can
* differ for each ezcCacheStorage implementation, but will most likely
- * be a filesystem path to a directory where cache data is stored in.
+ * be a filesystem path to a directory where cache data is stored in. The
+ * location is null for memory storage and an existing writeable path
+ * for file or memory/file storage.
*
* Per default there is only 1 common option for all ezcCacheStorage
* classes, which is the 'ttl' ( Time-To-Life ). This is per default set
* to 1 day. Specific ezcCacheStorage implementations can have
* additional options.
*
- * @param string $location Path to the cache location
+ * @param string $location Path to the cache location. Null
for
+ * memory-based storage and an
existing
+ * writeable path for file or
memory/file
+ * storage.
* @param array(string=>string) $options Options for the cache.
*
* @throws ezcBaseFileNotFoundException
Modified: trunk/Cache/src/storage/apc.php
==============================================================================
--- trunk/Cache/src/storage/apc.php [iso-8859-1] (original)
+++ trunk/Cache/src/storage/apc.php [iso-8859-1] Fri Oct 5 14:41:33 2007
@@ -50,7 +50,7 @@
* @param string $location Path to the cache location
* @param array(string=>string) $options Options for the cache
*/
- public function __construct( $location, array $options = array() )
+ public function __construct( $location = null, array $options = array() )
{
parent::__construct( $location, array() );
Modified: trunk/Cache/src/storage/apc/apc_array.php
==============================================================================
--- trunk/Cache/src/storage/apc/apc_array.php [iso-8859-1] (original)
+++ trunk/Cache/src/storage/apc/apc_array.php [iso-8859-1] Fri Oct 5 14:41:33
2007
@@ -33,7 +33,7 @@
* @throws ezcBasePropertyNotFoundException
* If you tried to set a non-existent option value.
*
- * @param string $location Path to the cache location
+ * @param string $location Path to the cache location. Must be a valid path
* @param array(string=>string) $options Options for the cache storage
*/
public function __construct( $location, array $options = array() )
Modified: trunk/Cache/src/storage/memcache.php
==============================================================================
--- trunk/Cache/src/storage/memcache.php [iso-8859-1] (original)
+++ trunk/Cache/src/storage/memcache.php [iso-8859-1] Fri Oct 5 14:41:33 2007
@@ -51,7 +51,7 @@
* @param string $location Path to the cache location
* @param array(string=>string) $options Options for the cache
*/
- public function __construct( $location, array $options = array() )
+ public function __construct( $location = null, array $options = array() )
{
parent::__construct( $location, array() );
Modified: trunk/Cache/src/storage/memory.php
==============================================================================
--- trunk/Cache/src/storage/memory.php [iso-8859-1] (original)
+++ trunk/Cache/src/storage/memory.php [iso-8859-1] Fri Oct 5 14:41:33 2007
@@ -73,7 +73,10 @@
* options depend on the ezcCacheStorage implementation and may
* vary.
*
- * @param string $location Path to the cache location
+ * @param string $location Path to the cache location. Null for
+ * memory-based storage and an existing
+ * writeable path for file or memory/file
+ * storage.
* @param array(string=>string) $options Options for the cache
*/
public function __construct( $location, array $options = array() )
Modified: trunk/Cache/tests/manager_test.php
==============================================================================
--- trunk/Cache/tests/manager_test.php [iso-8859-1] (original)
+++ trunk/Cache/tests/manager_test.php [iso-8859-1] Fri Oct 5 14:41:33 2007
@@ -29,6 +29,8 @@
'ezcCacheStorageFilePlain',
'ezcCacheStorageFileArray',
'ezcCacheStorageFileEvalArray',
+ 'ezcCacheStorageApcPlain',
+ 'ezcCacheStorageFileApcArray'
);
/**
@@ -144,6 +146,46 @@
$this->fail( 'ezcCacheInvalidIdException not thrown on invalid ID.' );
}
+ public function testCreateCacheFailUnreadable()
+ {
+ $temp = $this->createTempDir( __CLASS__ );
+ $location = $temp . DIRECTORY_SEPARATOR . 'subpath';
+ mkdir( $location );
+ chmod( $location, 0 );
+ try
+ {
+ ezcCacheManager::createCache( 'unreadable', $location,
'ezcCacheStorageFilePlain' );
+ $this->fail( "Expected exception was not thrown." );
+ }
+ catch ( ezcBaseFilePermissionException $e )
+ {
+ $this->assertEquals( true, strpos( $e->getMessage(), "Cache
location is not readable" ) !== false );
+ }
+
+ chmod( $location, 0777 );
+ $this->removeTempDir( $temp );
+ }
+
+ public function testCreateCacheFailUnwritable()
+ {
+ $temp = $this->createTempDir( __CLASS__ );
+ $location = $temp . DIRECTORY_SEPARATOR . 'subpath';
+ mkdir( $location );
+ chmod( $location, 0444 );
+ try
+ {
+ ezcCacheManager::createCache( 'unwritable', $location,
'ezcCacheStorageFilePlain' );
+ $this->fail( "Expected exception was not thrown." );
+ }
+ catch ( ezcBaseFilePermissionException $e )
+ {
+ $this->assertEquals( true, strpos( $e->getMessage(), "Cache
location is not writeable" ) !== false );
+ }
+
+ chmod( $location, 0777 );
+ $this->removeTempDir( $temp );
+ }
+
public function testGetCacheDelayedInit1()
{
try
Modified: trunk/Cache/tests/storage_apc_array_test.php
==============================================================================
--- trunk/Cache/tests/storage_apc_array_test.php [iso-8859-1] (original)
+++ trunk/Cache/tests/storage_apc_array_test.php [iso-8859-1] Fri Oct 5
14:41:33 2007
@@ -235,6 +235,21 @@
$this->assertEquals( true, 8 <= $lifetime );
}
+ public function testCacheManagerLocationEmpty()
+ {
+ $options = array( 'ttl' => 10 );
+ ezcCacheManager::createCache( 'memory', null,
'ezcCacheStorageFileApcArray', $options );
+ try
+ {
+ $storage = ezcCacheManager::getCache( 'memory' );
+ $this->fail( "Expected exception was not thrown" );
+ }
+ catch ( ezcBaseFilePermissionException $e )
+ {
+ $this->assertEquals( "The file '/' can not be opened for writing.
(Cache location is not a directory.)", $e->getMessage() );
+ }
+ }
+
public function testStorageFileApcArrayOptions()
{
$options = new ezcCacheStorageFileApcArrayOptions();
Modified: trunk/Cache/tests/storage_apc_plain_test.php
==============================================================================
--- trunk/Cache/tests/storage_apc_plain_test.php [iso-8859-1] (original)
+++ trunk/Cache/tests/storage_apc_plain_test.php [iso-8859-1] Fri Oct 5
14:41:33 2007
@@ -178,6 +178,15 @@
}
+ public function testCacheManagerLocationEmpty()
+ {
+ $options = array( 'ttl' => 10 );
+ ezcCacheManager::createCache( 'cache', null,
'ezcCacheStorageApcPlain', $options );
+ $storage = ezcCacheManager::getCache( 'cache' );
+ $storage->store( 'key', 'data' );
+ $this->assertEquals( 'data', $storage->restore( 'key' ) );
+ }
+
public function testStorageApcOptions()
{
$options = new ezcCacheStorageApcOptions();
Modified: trunk/Cache/tests/storage_memcache_plain_test.php
==============================================================================
--- trunk/Cache/tests/storage_memcache_plain_test.php [iso-8859-1] (original)
+++ trunk/Cache/tests/storage_memcache_plain_test.php [iso-8859-1] Fri Oct 5
14:41:33 2007
@@ -212,6 +212,15 @@
}
+ public function testCacheManagerLocationEmpty()
+ {
+ $options = array( 'host' => 'localhost', 'port' => 11211, 'ttl' => 10
);
+ ezcCacheManager::createCache( 'cache', null,
'ezcCacheStorageMemcachePlain', $options );
+ $storage = ezcCacheManager::getCache( 'cache' );
+ $storage->store( 'key', 'data' );
+ $this->assertEquals( 'data', $storage->restore( 'key' ) );
+ }
+
public function testStorageMemcacheOptions()
{
$options = new ezcCacheStorageMemcacheOptions();
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components