Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [ZendFramework] Zend_Cache
Forum PHP.pl > Forum > PHP > Frameworki
nexis
Jak użyć Zend_Cache w boostrap, żeby analizując żądania wrzucał i wyciągał z cache?

W dokumentacji piszą tak:

  1. <?php
  2. /*
  3.  * You should avoid putting too many lines before the cache section.
  4.  * For example, for optimal performances, "require_once" or
  5.  * "Zend_Loader::loadClass" should be after the cache section.
  6.  */
  7.  
  8. $frontendOptions = array(
  9.   'lifetime' => 7200,
  10.   'debug_header' => true, // for debugging
  11.   'regexps' => array(
  12.       // cache the whole IndexController
  13.       '^/$' => array('cache' => true),
  14.  
  15.       // cache the whole IndexController
  16.       '^/index/' => array('cache' => true),
  17.  
  18.       // we don't cache the ArticleController...
  19.       '^/article/' => array('cache' => false),
  20.  
  21.       // ... but we cache the "view" action of this ArticleController
  22.       '^/article/view/' => array(
  23.           'cache' => true,
  24.  
  25.           // and we cache even there are some variables in $_POST
  26.           'cache_with_post_variables' => true,
  27.  
  28.           // but the cache will be dependent on the $_POST array
  29.           'make_id_with_post_variables' => true
  30.       )
  31.   )
  32. );
  33.  
  34. $backendOptions = array(
  35.    'cache_dir' => '/tmp/'
  36. );
  37.  
  38. // getting a Zend_Cache_Frontend_Page object
  39. $cache = Zend_Cache::factory('Page',
  40.                             'File',
  41.                             $frontendOptions,
  42.                             $backendOptions);
  43.  
  44. $cache->start();
  45. // if the cache is hit, the result is sent to the browser and the
  46. // script stop here
  47.  
  48. // [...] the end of the bootstrap file
  49. // these lines won't be executed if the cache is hit
  50. ?>


Ale żadnego żądania nie cache-uje. Cały plik index.php wygląda tak:

  1. <?php
  2.  
  3. // Define path to application directory
  4. defined('APPLICATION_PATH')
  5.    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
  6.  
  7. // Define application environment
  8. defined('APPLICATION_ENV')
  9.    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
  10.  
  11. // Ensure library/ is on include_path
  12. set_include_path(implode(PATH_SEPARATOR, array(
  13.    realpath(APPLICATION_PATH . '/../library'),
  14. )));
  15.  
  16. // Cache
  17. require_once 'Zend/Cache.php';
  18. $frontendOptions = array(
  19.    // cache for 1 hour
  20.    'lifetime' => 3600,
  21.    // Disable caching by default for all URLs
  22.    'default_options' => array(
  23.        'cache' => false
  24.    ),
  25.    // Only cache URLs for Index and News controllers
  26.    // matching the following patterns
  27.    'regexps' => array(
  28.        '^/$' => array('cache' => true),
  29.        '^/index/index/' => array('cache' => true),
  30.        '^/news/' => array('cache' => true),
  31.        '^/blog/tags/' => array('cache' => true)
  32.    )
  33. );
  34. $backendOptions = array(
  35.    'cache_dir' => APPLICATION_PATH . '/cache/'
  36. );
  37. // Note: APC backend has no options!
  38. $cache = Zend_Cache::factory(
  39.    'Page',
  40.    'File',
  41.    $frontendOptions,
  42.    $backendOptions
  43. );
  44. // Serve cached page (if it exists) and exit
  45. // otherwise cache all output after this point
  46. // assuming caching is enabled for the current URL
  47. $cache->start();
  48.  
  49. /** Zend_Application */
  50. require_once 'Zend/Application.php';
  51.  
  52. // Create application, bootstrap, and run
  53. $application = new Zend_Application(
  54.    APPLICATION_ENV,
  55.    APPLICATION_PATH . '/configs/application.ini'
  56. );
  57. $application->bootstrap()
  58.            ->run();
  59. ?>
dafi
jako domyślne ustawienia Zend_Cache_Frontend_Page
masz:
  1. <?php
  2. 'cache_with_get_variables' => false,
  3. 'cache_with_post_variables' => false,
  4. 'cache_with_session_variables' => false,
  5. 'cache_with_files_variables' => false,
  6. 'cache_with_cookie_variables' => false,
  7. ?>


zatem upewnij się że nie masz nic w tablicach $_POST,$_GET itd.
albo zezwól na cachowanie w przypadku ich znalezienia.

ustawiając np:
  1. <?php
  2. '^/$' => array(
  3.  'cache' => true,
  4.  'cache_with_cookie_variables' => true
  5. ),
  6. ?>


ewentualnie możesz jeszcze wywoływać aplikacje z podfolderu roota tj. http://localhost/jakis_katalog/controller/akcja

wtedy powinieneś użyć:

  1. <?php
  2. '^/jakis_katalog/$' => array(
  3.  'cache' => true,
  4.  'cache_with_cookie_variables' => true
  5. ),
  6. ?>
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.