CachedTemplate: A generalized template caching class

Release information

New: (1.4) Added support for reading into a variable the contents of a cached file, which can be used for partial caching of page contents. An example (partial_caching.php) is included to illustrate the use of the method.

New: (1.3, unreleased) Added a locking mechanism to avoid race conditions while updating a cached file

(1.2) Added a general way of using user's variables for writing/reading/validating cached information. Added support for external data validation. NOTE: For questions about these classes contact me at: This email address is being protected from spambots. You need JavaScript enabled to view it. , any e-mail related to these classes going to any of my other e-mail addresses will go unanswered.

History

  • 2000-06-10: Initial release of code
  • 2000-07-12: I finally wrote the documentation
  • 2000-07-16: Added support for PHPLIB's template class. Added support for use of the GET query string to generate various cached files from the same script (method use_get). Changed my e-mail in the code. Updated the documentation
  • 2000-07-18: Added support for external data validation (version not released)
  • 2000-07-30: Reorganization of the code to use a general method for filename generation (_gen_filename), modified the external data validation method
  • , and modified the use of user variables when writing/reading/validating cache to be more general, added the methods use_vars and _gen_var_val, eliminated the internal variable $USEGET in favor of 2 new variables $USEVARS and VARSVAL.
  • 2000-07-31: Added an example on how to use use_vars, modified the examples of is_data_valid, some minor code cleaning and updated the documentation. Renamed the example files get_example[12].php to use_get_example[12].php. New release: version 1.2
  • 2000-08-02: Found a typo that was causing errors in the read_from_cache method. Only happened in some cases when using the "in_name" option of use_get or use_vars
  • 2000-09-05: Fixed mispelt "$release" var in code and the 13 typos in the previous documentation
  • 2000-10-07: Added locking mechanism to the class (version 1.3, unreleased)
  • 2001-02-06: Merged (modified) contributed code from Matthieu Casanova, which allows reading from cached files into a variable. This can be used to cache blocks of content in a page (or pages). New release: version 1.4

Known bugs

Bugs? this code is prefect :-) If you do find a bug, contact me at the address: jmcastagnetto at php dot net (indicate "CachedTemplate BUG" in the subject)

License

(from the GPL license)
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

[Go to the URL: http://www.fsf.org/copyleft/gpl.html for the full text of the GPL License]

Download

  • Get Everything
    The CachedTemplate class, the TemplateAdapter classes, and the examples as a .zip or a .tar.gz archive (documentation included, ZIP created using GNU infozip).

    Below is the list of files included in the distribution:
    1. CachedTemplate.html - this document
    2. class.CachedTemplate.php - the CachedTemplate class
    3. Files related to CDI's Fastemplate class
      • class.FastTemplate.php3 - the template class
      • class.FastTemplateAdaptor.php - the adaptor class
      • fasttemplate_example.php - example
      • templates/main.tpl - template used in the example
      • templates/table.tpl - template used in the example
      • templates/row.tpl - template used in the example
      • use_get_example1.php - example using use_get ("in_name" option)
      • use_vars_example.php - example using use_vars ("store" option)
      • datavalid_example1.php - example using external data validation ("timestamp")
      • partial_caching.php - example using get_from_cache to show how caching of sections of a page can be implemented
    4. Files related to Herman's HTML Template class
      • herman_template.inc - the template class
      • class.HTMLTemplateAdaptor.php - the adaptor class
      • herman_example.php - example
      • herman_template.html - template used in the example
    5. Files related to Stefan's QuickTemplate class
      • class.QuickTemplate.php3 - the template class
      • class.QuickTemplateAdaptor.php - the adaptor class
      • quicktemplate_ex.php - example
      • first_example.tpl - template used in the example
    6. Files related to Richard's Template class
      • class.template.inc - the template class
      • class.RHTemplateAdaptor.php - the adaptor class
      • richard_example.php - example
      • header-template.html - template used in the example
      • main-template.html - template used in the example
      • footer-template.html - template used in the example
    7. Files related to Barnabás' XTemplate class
      • xtpl.php - the template class
      • class.XTemplateAdaptor.php - the adaptor class
      • xtemplate_ex5.php - example
      • ex5.xtpl - template used in the example
    8. Files related to PHPLIB's Template class
      • phplib_template.inc - the template class
      • class.PHPLIBTemplateAdaptor.php - the adaptor class
      • phplibtemplate_example.php - example
      • ptpl_box.ihtml - template used in the example
      • ptpl_page.ihtml - template used in the example
      • get_example2.php - example using use_get ("store" option)
      • datavalid_example2.php - example using external data validation ("md5")
    9. Miscellaneous files
      • COPYING - the GPL license version
      • LICENSE - the copyright and license notice for this package
      • rows.dat - data used in the datavalid_example[12].php files

Acknowledgements

Thanks to the people who sent suggestions, requests and bug reports: (email addresses mangled in HTML code, to prevent spambot harvesting)
  • Jackson Tsai (This email address is being protected from spambots. You need JavaScript enabled to view it. ) - GET query string use (feature request)
  • DK Kim (This email address is being protected from spambots. You need JavaScript enabled to view it. ) - typo in class.XTemplateAdaptor.php
  • Skirando C. Philipona (This email address is being protected from spambots. You need JavaScript enabled to view it. ) - PHPLIB's Template support (feature request)
  • Brad Atkins (This email address is being protected from spambots. You need JavaScript enabled to view it. ) - Idea/request that lead to adding the data validation methods
  • Toby Champion (This email address is being protected from spambots. You need JavaScript enabled to view it. ) - for finding the mispelt "$release" var name in the class code, and for considering that 13 typos in the documentation consists sloppy typing, that will make me use ispell more often
  • Andreas Mock (This email address is being protected from spambots. You need JavaScript enabled to view it. ) - for realizing that there could be a race condition when updating a cached file, which prompted the creation of the locking methods
  • Matthieu Casanova (This email address is being protected from spambots. You need JavaScript enabled to view it. ) - for contributing a method to read cached files into variables, allowing for partial caching of content in pages

Our son is here!

Our son Daniel Ken was born on March 09, 2009 at 14:39 PET (UTC - 5). We are happier than we've ever been in our lives.

Now the real work begins, helping a new life develop into this world.

-- Mom and Dad

My Random Photo

From Airin's Photo Gallery

Green Hosting at Dreamhost.com