Welcome Guest, Not a member yet? Register   Sign In
Sparks : Caching Template system
#2

[eluser]Al James[/eluser]
Hi there...

Here is the 'Sparks.php' library.

As well as two-stage caching, this library also solves the view within a view problem commonly experienced with 'templated' webpages. You set a 'template' view file and also a 'content' view file (the template one is optional though). In your template you use the helper 'sparks_content()' as a placemarker where the content file should be inserted. You can also include views within views using the 'sparks_include($view_file)' helper.

Usage (Controller):

Code:
class Test extends Controller {
    
    function index()
    {
        $this->load->library('Sparks');
        //$this->import->library('com.purplesagelabs.template.Sparks');
        
        //     Set template and content files. Set time to live to 5 seconds.
        
        $this->sparks->template('template.php')->content('content.php')->ttl(5);
        
        //    Calculate data for non-cacheable content
        
        $this->sparks->set('username', 'Al James'); //Would be get username from session or whatever
        $this->sparks->set('view_time', time());
        
        // Check for cached version of page, if its there display it and return
        
        if ($this->sparks->is_cached()) return $this->sparks->display();
        
        //Otherwise, generate cacheable content
        
        $this->sparks->set('headline', 'Welcome to Sparks!');
        $this->sparks->set('generate_time', time());
        
        // Store and display the page
        
        $this->sparks->store()->display();
        
    }
}

Usage (template file)

Code:
<html>
<body>

    <h1>Template header!</h1>
    
    &lt;?php sparks_content(); ?&gt;

&lt;/body&gt;
&lt;/html&gt;


Usage (content file)

Code:
<h4>Content file. Todays headline: &lt;?= $headline ?&gt;</h4>

Username <$?= $username ?$> <br/>
Cache file generated at: &lt;?= $generate_time ?&gt;, this page generated at: <$?= $view_time ?$>


Messages In This Thread
Sparks : Caching Template system - by El Forum - 07-14-2007, 02:52 PM
Sparks : Caching Template system - by El Forum - 07-16-2007, 04:41 AM
Sparks : Caching Template system - by El Forum - 07-16-2007, 06:28 AM
Sparks : Caching Template system - by El Forum - 07-23-2007, 04:55 AM
Sparks : Caching Template system - by El Forum - 07-25-2007, 09:28 AM
Sparks : Caching Template system - by El Forum - 07-25-2007, 10:04 AM
Sparks : Caching Template system - by El Forum - 07-25-2007, 10:12 AM
Sparks : Caching Template system - by El Forum - 07-25-2007, 10:17 AM
Sparks : Caching Template system - by El Forum - 07-26-2007, 06:45 AM
Sparks : Caching Template system - by El Forum - 07-26-2007, 08:02 AM
Sparks : Caching Template system - by El Forum - 07-26-2007, 08:07 AM
Sparks : Caching Template system - by El Forum - 07-26-2007, 08:39 AM
Sparks : Caching Template system - by El Forum - 07-26-2007, 09:17 AM
Sparks : Caching Template system - by El Forum - 07-26-2007, 09:21 AM
Sparks : Caching Template system - by El Forum - 07-26-2007, 09:35 AM
Sparks : Caching Template system - by El Forum - 07-26-2007, 03:04 PM
Sparks : Caching Template system - by El Forum - 07-26-2007, 07:39 PM
Sparks : Caching Template system - by El Forum - 07-27-2007, 01:19 AM
Sparks : Caching Template system - by El Forum - 07-27-2007, 05:26 AM
Sparks : Caching Template system - by El Forum - 07-27-2007, 07:10 AM
Sparks : Caching Template system - by El Forum - 08-02-2007, 07:15 AM
Sparks : Caching Template system - by El Forum - 08-13-2007, 12:53 PM
Sparks : Caching Template system - by El Forum - 09-24-2007, 05:32 AM
Sparks : Caching Template system - by El Forum - 09-24-2007, 01:35 PM



Theme © iAndrew 2016 - Forum software by © MyBB