ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

template caching with php

February 24, 2011 7:04am

Subscribe [4]
  • #1 / Feb 24, 2011 7:04am

    Joobs

    362 posts

    I have some php in an embedded template that collects all the members from a twitter list.  However I only want this script to once every hour so we keep the number of requests to twitter low.

    If I turned on template caching for this embedded template with refresh set to 60, would that mean my script would only run once an hour?

    This script is only used on one page.

  • #2 / Feb 24, 2011 9:44am

    Mark Bowen

    12637 posts

    Refresh doesn’t mean that the template will run its contents. You would need a cron job for that.

    That or the code would need to be on a template which you know for a fact is going to get lots of hits although saying that caching works more like this.

    This is probably a bad example but hopefully it will get the idea across. Say you have a page with the latest news items on it (10 showing). You set the template caching to 60 minutes. You visit that page and see the news items. What this now means is that you could post another 100 news items but none of them will show up on that page until 60 minutes have passed even though they are valid weblog entries which would otherwise normally show up.

    Once the 60 minutes have passed then new items would show and so on and so forth.

    Caching just creates a sort of static page until the cache runs out and then it creates a new one if there are changes. Using caching however does not mean that the page will run once every hour. As mentioned above you would need to run a cron job in order for that to happen.

    Best wishes,

    Mark

  • #3 / Feb 24, 2011 10:00am

    Joobs

    362 posts

    I didn’t really mean I needed it to run every hour, i just wanted to stop it calling twitter on every refresh. I have a single page that is displaying the twitter list and wanted an easy way to make sure that page didn’t call up twitters api on every page refresh.  So it would send a maximum of 24 requests a day rather than 10,000.

    I think template caching works per url and not per template.  So i realise if i wanted to put that list on every page then it would be making extra API calls per page.

    But since i am only having it on one page, I was thinking this would be a very quick solution?

  • #4 / Feb 24, 2011 3:57pm

    Ingmar

    29245 posts

    Since this is not an EE issue as such I’m going to move this to General. Thanks.

  • #5 / Feb 24, 2011 4:29pm

    Ryan Battles

    63 posts

    If that doesn’t work out for you, you can use Solspace’s Template Morsels, which would allow you to create a snippet that gets custom caching treatment.  We use that module on Director-ee when trying to limit the number of requests we make to the Google Maps API, while speeding up the loading of about 700 pins on the map 😊

  • #6 / Feb 26, 2011 11:24am

    John Fuller

    779 posts

    Take a look at this plugin.  Kind of goes along with one of Mark’s suggestions.

    http://devot-ee.com/add-ons/expressionengine-cron/

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases