Show
Ignore:
Timestamp:
12/09/2007 01:10:07 AM (13 months ago)
Author:
Shadowhand
Message:

Updating forge_demo/edit_user with caching.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/modules/forge/controllers/forge_demo.php

    r1474 r1475  
    4141        { 
    4242                $profiler = new Profiler; 
     43                $cache = new Cache; 
    4344 
     45                // Cache id for the current empty editing form 
     46                $cache_id = 'form--'.url::current(); 
     47 
     48                if (empty($_POST)) 
     49                { 
     50                        // Attempt to get the HTML from cache 
     51                        if ($form = $cache->get($cache_id)) 
     52                        { 
     53                                echo $form; 
     54                                return; 
     55                        } 
     56                } 
     57 
     58                // Create a new user editing form 
    4459                $form = new User_Edit_Model(NULL, 'Edit User', $id); 
    4560 
    4661                if ($form->save()) 
    4762                { 
     63                        // Cache information is no longer valid 
     64                        $cache->del($cache_id); 
     65 
    4866                        echo Kohana::debug('user edited!', $form->as_array()); 
     67                } 
     68 
     69                if (empty($_POST)) 
     70                { 
     71                        // Cache the form HTML 
     72                        $cache->set($cache_id, $form = $form->html()); 
    4973                } 
    5074