Blog of Timur Asaliev
RSS icon Email icon Home icon
  • PHP Template Caching

    Posted on January 8th, 2009 Timur Asaliev No comments

    This new year brought some inspiration in respect of coding to me and I have decided to research and possibly implement my own template caching system. I have looked around for some solutions but I wasn’t able to locate a system that could handle partial caching, although this could just be my poor googling skills. By partial caching I mean caching the whole template (for example: the <head> section which might be generated automatically, the body with the news and the comments) but don’t cache blocks of data of my choice. A good example of these blocks could be a box looking like this:

    Welcome back, DummyUser (link to personal profile)
    You have X new messages

    So I have spent two days to put down the list of features I want on paper so here it goes:

    • Easy to integrate with other PHP aplications.
    • An ability to work with <meta> tags, <script> and <link> includes.
    • Per template caching on-demand.
    • Caching of whole pages (based on REQUEST_URI) but with an option for non cached blocks of data (example above).
    • Assignment of template variables.
    • Dynamic generation of page titles.

    Some of the features are already implemented (and are working!), like caching of templates on demand and caching of whole pages with ability to leave non cached blocks of data.

    Hopefully this inspiration will stay for a couple of more days so I accually post a stable version of the class for others to explore and play around with.