Should I use Smarty caching or cache-control headers in .htaccess?

Posted on 2009-02-18
Last Modified: 2012-05-06
Hello experts,

I'm using software written in PHP that uses the smarty templating system. I have set up image caching for the site using cache-control headers, but now I want to cache the html output also. On some pages I want to cache nothing, and on others I want to cache everything, and on others I would like to be able to selectively cache some parts (the output of other subtemplates, which are separate .tpl files).

My question is, should I even bother with smarty? If I do it with cache-control, I won't be able to cache only parts of pages I guess, but I can live with that. Is there a compelling reason to use smarty instead, or use both together?

Thanks for any insight you can provide.

Question by:utzi
    LVL 1

    Accepted Solution

    Here Smarty and Cache Control do  completely different things.

    Smarty caches the rendered output of defined areas of your templates. That's for a cross-client fonctionnality. One client comes, hits and cache a page. The second will hit the page and get directly the cached content, thus limiting the load on your server.

    Cache-control works for only one client. It is a browser-side caching. It means if you get 100 000 different users looking your frontpage, for all of them the server will compute its content.

    My best advice... if your site is used by a very little amount of people, often refreshing, then cache-control can be good. Any other case will give a 100 times better result with Smarty caching.
    The 2 are entirely compatible though!

    Author Comment


    Thank you for your comments. I understand the difference and turned on smarty caching to test it out. Everything looked good, until I found that the caching broke parts of my admin area (which is run by smarty too). I will try implementing smarty caching on appropriate pages (that receive the most traffic), but not as a blanket solution, because of this.

    Thank you very much!


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    The viewer will learn how to count occurrences of each item in an array.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now