• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 688
  • Last Modified:

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

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.

1 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!
utziAuthor Commented:

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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now