Author: dr
Date: Tue Aug 14 13:12:58 2007
New Revision: 5912

Log:
- Implemented issue #10533: ezcCacheManager::getCache does not support delayed
  initialization.

Added:
    trunk/Cache/tests/test_classes.php   (with props)
Modified:
    trunk/Cache/ChangeLog
    trunk/Cache/docs/tutorial.txt
    trunk/Cache/src/manager.php
    trunk/Cache/tests/manager_test.php

Modified: trunk/Cache/ChangeLog
==============================================================================
--- trunk/Cache/ChangeLog [iso-8859-1] (original)
+++ trunk/Cache/ChangeLog [iso-8859-1] Tue Aug 14 13:12:58 2007
@@ -1,3 +1,10 @@
+1.3alpha1 - [RELEASEDATE]
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+- Implemented issue #10533: ezcCacheManager::getCache does not support delayed
+  initialization.
+
+
 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] Tue Aug 14 13:12:58 2007
@@ -110,6 +110,31 @@
 data, so you can follow how it's cached for 30 seconds by running the
 example multiple times in a short time frame. After 30 seconds, the cache data
 will become invalid and will be regenerated.
+
+Delayed initialization
+----------------------
+
+Instead of calling the ezcCacheManager::getCache() method yourself it is also
+possible to use delayed initialization. When using this it is not required to
+configure all the caches first by calling the ezcCacheManager::createCache()
+method. Instead it would allow you to configure/create caches on demand, this
+is called lazy, or delayed initialization. You can find a description how you
+can use it for your own components and how it works in the `ezcBase
+tutorial`__. The keyword for the cache component is
+*ezcInitConfigurationManager*.
+
+__ introduction_Base.html#lazy-initialization
+
+.. include:: tutorial_lazy_initialization.php
+       :literal:
+
+Differences with the previous example can be seen in lines 5 to 23. In lines 20
+to 23 you tell the delayed initialization mechanism to use the
+customLazyCacheConfiguration as lazy initialization provider for the
+*ezcInitConfigurationManager* context. The customLazyCacheConfiguration class
+implements the configureObject() method that will automatically be called when
+ezcCacheManager::getCache() is called with a cache identifier that has not been
+created yet through ezcCacheManager::createCache(), as you can see in line 14.
 
 Using multiple caches
 ---------------------

Modified: trunk/Cache/src/manager.php
==============================================================================
--- trunk/Cache/src/manager.php [iso-8859-1] (original)
+++ trunk/Cache/src/manager.php [iso-8859-1] Tue Aug 14 13:12:58 2007
@@ -57,16 +57,22 @@
  * // instance will be reused.
  * $cache = ezcCacheManager::getCache( 'content' );
  *
+ * Instead of using the createCache()/getCache() mechanism you can also create
+ * cache on-demand with delayed initialization. You can find information on how
+ * to use that in the [EMAIL PROTECTED] ../introduction_Cache.html tutorial}.
+ *
  * // Specify any number of attributes to identify the cache item you want
  * // to store. This attributes can be used later to perform operations
  * // on a set of cache items, that share a common attribute.
  * $attributes = array( 'node' => 2, 'area' => 'admin', 'lang' => 'en-GB' );
+ *
  * // This function is not part of the Cache package. You have to define
  * // unique IDs for your cache items yourself.
  * $id = getUniqueId();
  *
  * // Initialize the data variable you want to restore
  * $data = '';
+ *
  * // Check if data is available in the cache. The restore method returns
  * // the cached data, if available, or bool false.
  * if ( ( $data = $cache->restore( $id, $attributes ) ) === false )
@@ -259,7 +265,14 @@
         // Look for already existing cache object
         if ( !isset( self::$caches[$id] ) ) 
         {
-            // Failed, look for configuration
+            // Failed, look for configuration, and if it does not exist, use
+            // delayed initialization.
+            if ( !isset( self::$configurations[$id] ) )
+            {
+                ezcBaseInit::fetchConfig( 'ezcInitCacheManager', $id );
+            }
+            // Check whether delayed initialization actually worked, if not,
+            // throw an exception
             if ( !isset( self::$configurations[$id] ) )
             {
                 throw new ezcCacheInvalidIdException( $id );

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] Tue Aug 14 13:12:58 2007
@@ -8,6 +8,8 @@
  * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
  * @license http://ez.no/licenses/new_bsd New BSD License
  */
+
+require_once 'test_classes.php';
 
 /**
  * Test suite for ezcCacheManager class. 
@@ -141,5 +143,25 @@
         }
         $this->fail( 'ezcCacheInvalidIdException not thrown on invalid ID.' );
     }
+
+    public function testGetCacheDelayedInit1()
+    {
+        try
+        {
+            $cache = ezcCacheManager::getCache( 'simple' );
+            self::fail( 'Expected exception not thrown.' );
+        }
+        catch ( ezcCacheInvalidIdException $e )
+        {
+            self::assertSame( "No cache or cache configuration known with ID 
'simple'.", $e->getMessage() );
+        }
+    }
+
+    public function testGetCacheDelayedInit2()
+    {
+        ezcBaseInit::setCallback( 'ezcInitCacheManager', 
'testDelayedInitCacheManager' );
+        $cache = ezcCacheManager::getCache( 'simple' );
+        self::assertSame( '.cache', $cache->options->extension );
+    }
 }
 ?>

Added: trunk/Cache/tests/test_classes.php
==============================================================================
--- trunk/Cache/tests/test_classes.php (added)
+++ trunk/Cache/tests/test_classes.php [iso-8859-1] Tue Aug 14 13:12:58 2007
@@ -1,0 +1,17 @@
+<?php
+class testDelayedInitCacheManager implements ezcBaseConfigurationInitializer
+{
+    static function configureObject( $identifier )
+    {
+        if ( $identifier !== false )
+        {
+            switch ( $identifier )
+            {
+                case 'simple':
+                    ezcCacheManager::createCache( $identifier, '/tmp', 
'ezcCacheStorageFilePlain' );
+                    break;
+            }
+        }
+    }
+}
+?>

Propchange: trunk/Cache/tests/test_classes.php
------------------------------------------------------------------------------
    svn:eol-style = native


-- 
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to