Zend_Application-AvailableResources-CacheManager.xml 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect2 id="zend.application.available-resources.cachemanager">
  4. <title>Zend_Application_Resource_Cachemanager</title>
  5. <para>
  6. <classname>Zend_Application_Resource_Cachemanager</classname> may be
  7. utilised to configure a set of <classname>Zend_Cache</classname> option
  8. bundles for use when lazy loading caches using
  9. <classname>Zend_Cache_Manager</classname>
  10. </para>
  11. <para>
  12. As the Cache Manager is a lazy loading mechanism, the options are translated
  13. to option templates used to instantiate a cache object on request.
  14. </para>
  15. <example id="zend.application.available-resources.cachemanager.configExample">
  16. <title>Sample Cachemanager resource configuration</title>
  17. <para>
  18. Below is a sample <acronym>INI</acronym> file showing how
  19. <classname>Zend_Cache_Manager</classname> may be configured. The format
  20. is the Cachemanager resource prefix (<property>resources.cachemanager</property>)
  21. followed be the name to assign to an option cache template or bundle (e.g.
  22. <property>resources.cachemanager.database</property>) and finally followed by a
  23. typical <classname>Zend_Cache</classname> option.
  24. </para>
  25. <programlisting language="ini"><![CDATA[
  26. resources.cachemanager.database.frontend.name = Core
  27. resources.cachemanager.database.frontend.customFrontendNaming = false
  28. resources.cachemanager.database.frontend.options.lifetime = 7200
  29. resources.cachemanager.database.frontend.options.automatic_serialization = true
  30. resources.cachemanager.database.backend.name = File
  31. resources.cachemanager.database.backend.customBackendNaming = false
  32. resources.cachemanager.database.backend.options.cache_dir = "/path/to/cache"
  33. resources.cachemanager.database.frontendBackendAutoload = false
  34. ]]></programlisting>
  35. <para>
  36. Actually retrieving this cache from the Cache Manager is as simple as
  37. accessing an instance of the Manager (<classname>Zend_Cache_Manager</classname>)
  38. retrieved from <classname>Zend_Application_Resource_Cachemanager</classname> and
  39. calling <methodname>Zend_Cache_Manager::getCache('database')</methodname>. The example
  40. below is taken from a controller where the bootstrap class can be accessed as
  41. a Front Controller parameter (which is automatically assigned during bootstrapping).
  42. As you can see, the Cache Manager Resource implements a
  43. <methodname>getCacheManager()</methodname> method to retrieve the bootstrapped instance
  44. of <classname>Zend_Cache_Manager</classname>.
  45. </para>
  46. <programlisting language="php"><![CDATA[
  47. $manager = $this->getFrontController()
  48. ->getParam('bootstrap')
  49. ->getPluginResource('cachemanager')
  50. ->getCacheManager();
  51. $dbCache = $manager->getCache('database');
  52. ]]></programlisting>
  53. <para>
  54. See <methodname>Zend_Cache::factory()</methodname> method to get a
  55. description of the default values you can assign when configuring a
  56. cache via a configuration file such as out example <acronym>INI</acronym> file above.
  57. </para>
  58. </example>
  59. </sect2>