Navigatore:   Home arrow Zend Controller - Note arrow zend controller page cache
Menu principale
Home
Credits
Zend Controller - Note
Notizie
Credits
Music Sense
RED5
Iped
- - - - - - -Mix
Il Tuo IP
Parole crociate - At Cross
1000 Games
Chi e' online
Abbiamo 13 visitatori online
-

zend controller page cache Stampa E-mail

Image


 Esempio per la realizazione di un sistema di cache basato sul metodo page di zend_cache.

se la pagina in questione è cachata non avviene per niente il dispach della pagine, viceversa viene presa direttamente col file get content php e salvata nella directory di cache.

l'id di cache sarà l'url univoco. 

Example of cache system based on page method of zend_cache.

If the request pase is cached is called cached one without dispach, if not  the request page is  get wiht php fiel get content and saved in cache dir.

the unique cache id will be the page url.

 


    require_once 'Zend/Cache.php';
        $id =  str_replace("/".PATH_FRONT."/",'',$_SERVER["REQUEST_URI"]);
        $id =  str_replace('/','',$id);
        if ($id != ""){
        $frontendOptions = array(
        'ignore_user_abort' => 'true',
        'lifetime' => 7200, // 2 ore di cache?
        'automatic_serialization' => true
        );
        }
        else{
        $id='home';
        $frontendOptions = array('ignore_user_abort' => 'true',
        'lifetime' => 3600, // 1 ore di cache sulla home??
        'automatic_serialization' => true
        );
        }
$backendOptions = array(
    'cache_dir' => './tmp_imgGal/' // Directory where to put the cache files
);

// getting a Zend_Cache_Core object
$cache = Zend_Cache::factory('Page',
                             'File',
                             $frontendOptions,
                             $backendOptions);
        
         $cache->start();
        
        //$id = 'cache'; // cache id of "what we want to cache"


if (!($data = $cache->load("$id"))) {
    // cache miss

        
        require_once 'Zend/Filter/StripTags.php';

        
        
        
        
        if ($_SERVER["HTTP_USER_AGENT"] == "")
        {
       
           $frontController = Zend_Controller_Front::getInstance();
        
        
        $frontController->dispatch();
        }else{
        
        $data=file_get_contents("http://localhost".$_SERVER["REQUEST_URI"]);
           }
           $cache->save($data);
           
  }        
    echo($data);    
    
   

 
< Prec.   Pros. >