Show
Ignore:
Timestamp:
10/07/08 11:03:16 (2 months ago)
Author:
arnoschn
Message:

WARNING: IMPORTANT CHANGES AHEAD!

Using this version requires you do manually add/change files/folders to existing applications.

Merging Caching Branch into trunk:

New features:

1. Configuration

1.1. Yaml Configuration (see inline doc at: http://svn.akelos.org/trunk/lib/AkConfig.php)

2. Caching (see inline doc at: http://svn.akelos.org/trunk/lib/AkActionController/AkCacheHandler.php)

2.1 Memcache Cache Handler
2.2 Page Caching
2.3 Action Caching
2.4 Fragment Caching
2.5 Cache Sweepers

3. ActiveRecord?

3.1 toXml (RoR style) (see inline doc at: http://svn.akelos.org/trunk/lib/AkActiveRecord.php)
3.2 fromXml
3.3 toJson (RoR style) (see inline doc at: http://svn.akelos.org/trunk/lib/AkActiveRecord.php)
3.4 fromJson
3.5 AkDbSchemaCache?

4. ActionController?

4.1 respondToFormat (see inline doc at: http://svn.akelos.org/trunk/lib/AkActionController.php)

5. Functional Testing (AkTestApplication?) (see example usage in: http://svn.akelos.org/trunk/test/unit/lib/AkActionController/_page_caching.php)

Refactoring / Improvements:

6. Unit Testing Fixtures

class AkSomeTest? extends AkUnitTest?
{
/**

  • grabs AK_BASE_DIR/test/fixtures/data/posts.yaml and inserts the data in the db
  • example:

  • posts.yaml:
  • entry1:
  • id: 1
  • name: test1
  • entry2:
  • id: 2
  • name: test2

  • model instances are available via $this->posts['entry1] and $this->posts['entry2]
    */
    var $fixtures = 'posts';


...

}

7. AkSession?


Session handling can now be configured via config/sessions.yml.
Besides file storage you can use Memcache or Db Storage for sessions.

8. AkPluginInstaller?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk

    • Property svn:ignore changed from
      tmp/*
      to
      .project
  • trunk/lib/AkCache.php

    r549 r1185  
    9999    */ 
    100100    var $cache_enabled = true; 
    101  
     101     
     102     
     103    /** 
     104     * Instantiates and configures the AkCache store. 
     105     *  
     106     * If $options == NULL the configuration will be taken from the constants: 
     107     *  
     108     * AK_CACHE_HANDLER and AK_CACHE_OPTIONS 
     109     *  
     110     * if $options is of type string/int the $options parameter will be considered 
     111     * as the AK_CACHE_HANDLER_* Type (AK_CACHE_HANDLER_PEAR,AK_CACHE_HANDLER_ADODB,AK_CACHE_HANDLER_MEMCACHE) 
     112     *  
     113     * if $options is an array of format: 
     114     *  
     115     *   array('file'=>array('cacheDir'=>'/tmp')) 
     116     *    
     117     *   or 
     118     *  
     119     *   array(AK_CACHE_HANDLER_PEAR=>array('cacheDir'=>'/tmp')) 
     120     *  
     121     *  the first key will be used as the AK_CACHE_HANDLER_* Type 
     122     *  and the array as the config options 
     123     *  
     124     * Default behaviour is calling the method with the $options == null parameter: 
     125     *  
     126     * AkCache::lookupStore() 
     127     *  
     128     * Calling it with: 
     129     *  
     130     * AkCache::lookupStore(true) 
     131     *  
     132     * will return the configured $cache_store 
     133     * 
     134     * @param mixed $options 
     135     * @return mixed   false if no cache could be configured or AkCache instance 
     136     */ 
     137    function &lookupStore($options = null) 
     138    { 
     139        static $cache_store; 
     140        $false = false; 
     141        if ($options === true && !empty($cache_store)) { 
     142            return $cache_store; 
     143        } else if (is_array($options) &&  
     144                   isset($options['enabled']) && $options['enabled']==true && 
     145                   isset($options['handler']) && 
     146                   isset($options['handler']['type'])) { 
     147            $type = $options['handler']['type']; 
     148            $options = isset($options['handler']['options'])?$options['handler']['options']:array(); 
     149        } else if (is_string($options) || is_int($options)) { 
     150            $type = $options; 
     151            $options = array(); 
     152        } else { 
     153            return $false; 
     154        } 
     155        $cache_store = new AkCache(); 
     156        $cache_store->init($options,$type); 
     157        if ($cache_store->cache_enabled) { 
     158            return $cache_store; 
     159        } 
     160        return $false; 
     161    } 
     162     
     163    function expandCacheKey($key, $namespace = null) 
     164    { 
     165        $expanded_cache_key = $namespace != null? $namespace : ''; 
     166        if (isset($_ENV['AK_CACHE_ID'])) { 
     167            $expanded_cache_key .= DS . $_ENV['AK_CACHE_ID']; 
     168        } else if (isset($_ENV['AK_APP_VERSION'])) { 
     169            $expanded_cache_key .= DS . $_ENV['AK_APP_VERSION']; 
     170        } 
     171         
     172        if (is_object($key) && method_exists($key,'cacheKey')) { 
     173            $expanded_cache_key .= DS . $key->cacheKey(); 
     174        } else if (is_array($key)) { 
     175            foreach ($key as $idx => $v) { 
     176                $expanded_cache_key .= DS . $idx.'='.$v; 
     177            } 
     178        } else { 
     179            $expanded_cache_key .= DS . $key; 
     180        } 
     181        $regex = '|'.DS.'+|'; 
     182        $expanded_cache_key = preg_replace($regex,DS, $expanded_cache_key); 
     183        $expanded_cache_key = rtrim($expanded_cache_key,DS); 
     184        return $expanded_cache_key; 
     185    } 
    102186     
    103187    /** 
     
    147231    * - 1: File based cache using the folder defined at AK_CACHE_DIR or the system /tmp dir 
    148232    * - 2: Database based cache. This one has a performance penalty, but works on most servers 
     233    * - 3: Memcached - The fastest option 
    149234    * @return void 
    150235    */ 
    151     function init($options = null, $cache_type = AK_CACHE_HANDLER
     236    function init($options = null, $cache_type = null
    152237    { 
    153238        $options = is_int($options) ? array('lifeTime'=>$options) : (is_array($options) ? $options : array()); 
     
    160245                } 
    161246                if(!isset($options['cacheDir'])){ 
    162                     if(!is_dir(AK_CACHE_DIR)){ 
    163                         Ak::make_dir(AK_CACHE_DIR, array('base_path'=>AK_TMP_DIR)); 
    164                     } 
    165247                    $options['cacheDir'] = AK_CACHE_DIR.DS; 
     248                } else { 
     249                    $options['cacheDir'].=DS; 
     250                } 
     251                 if(!is_dir($options['cacheDir'])){ 
     252                    Ak::make_dir($options['cacheDir'], array('base_path'=>dirname($options['cacheDir']))); 
    166253                } 
    167254                $this->_driverInstance =& new Cache_Lite($options); 
    168255                break; 
    169256            case 2: 
    170                 $this->cache_enabled = true; 
    171257                require_once(AK_LIB_DIR.'/AkCache/AkAdodbCache.php'); 
    172258                $this->_driverInstance =& new AkAdodbCache(); 
    173                 $this->_driverInstance->init($options); 
     259                $res = $this->_driverInstance->init($options); 
     260                $this->cache_enabled = $res; 
     261                break; 
     262            case 3: 
     263                require_once(AK_LIB_DIR.'/AkCache/AkMemcache.php'); 
     264                $this->_driverInstance =& new AkMemcache(); 
     265                $res = $this->_driverInstance->init($options); 
     266                $this->cache_enabled = $res; 
    174267                break; 
    175268            default: 
     
    247340    } 
    248341 
    249  
    250342} 
    251343