Sep
23
2009

(Ab-)using Smarty cache in order to load Websources into own Webpage

This article discribes an easy way to cache data received from other websites in order to improve the performance of one own's site. The method was successfully tested on alexander-kaletsch.de (blog) and birgit-kaletsch.de (kurse-detail).

Theory: Download Websource only after cache got invalid.

First you have to create a dummy template: _cache.tpl

{$cache}

The index.php:

require_once("Smarty/Smarty.class.php");

$smarty = new Smarty();

$smarty->compile_dir     = "_comp/";
$smarty->template_dir     = "tpl/";
$smarty->cache_dir        = "_cache/";
$smarty->cache_lifetime = 60*60; // 1h

$smarty->caching = 2;

if(!$smarty->is_cached("_cache.tpl", "blog")){
$smarty->assign("cache", file_get_contents("http://www.patworx.de/blog/index.php"));
}

echo $smarty->fetch("_cache.tpl", "blog");

if(!$smarty->is_cached("_cache.tpl", "ak")){
$smarty->assign("cache", file_get_contents("http://www.alexander-kaletsch.de/"));
}

echo $smarty->fetch("_cache.tpl", "ak");

Written by Alexander Kaletsch in: Allgemein |

Keine Kommentare »

RSS feed for comments on this post. TrackBack URL


Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Powered by WordPress | Theme: Aeros 2.0 by TheBuckmaker.com