Support » Plugins » Improved caching

  • I was using this code to cache delicious feeds in my sidebar; however whenever it couldn’t access delicious it would replace my feed with an ugly warning message. The delicious cached plugin does this better – but it falls short in that it doesn’t allow for multiple feeds. I solve this problem by creating a top level folder (writable by the system) called “delicious” and putting multiple copies of my own script with slightly different names for each feed. i.e. “” or “” – each producing a differently named cache file in the same folder. My script is an amalgam of the two scripts mentioned above, and I thought I’d share it because this has been very useful for me. Hopefully someone will eventually write a more robust delicious caching plugin which allows for multiple feeds from different tags.

    This example uses the tag “blogroll” and produces a cached file: “blogroll.html.”

    $username = "USERNAME";
    $user = "USERNAME/blogroll";
    $opts = "?count=20&tags=no&rssbutton=no&bullet=";
    $url = "";
    $cachefile = "delicious/blogroll.html"; // name of cache file
    $cachetime = 60 * 60; // 60 minutes

    // if cache is valid, just use it instead of hitting
    if (file_exists($cachefile) && (time() - $cachetime < filemtime($cachefile)))
    } else {
    $c = curl_init($url . $user . $opts);
    // cURL options
    curl_setopt($c, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($c, CURLOPT_USERPWD,"$username");
    curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 2);
    curl_setopt($c, CURLOPT_TIMEOUT, 4);
    curl_setopt($c, CURLOPT_USERAGENT, " cached 1.4 /");
    $response = curl_exec($c);
    $info = curl_getinfo($c);
    $_curl_error_code = $info['http_code'];

    if($_curl_error_code == 200) {
    echo $response;

    $fp = fopen($cachefile, 'w');
    fwrite($fp, $response);
    } else {

  • The topic ‘Improved caching’ is closed to new replies.