Re: [PHPTAL] Check if cached

2009-11-11 Thread Kornel Lesinski

On 11 Nov 2009, at 02:22, Andrew wrote:


Hello i've got a question and suggestion...

I am using CodeIgniter framework with PHPTAL and it works great, but  
there is
little problem with caching. I cant get a nice preformance boost  
because i

can't figure out how to check if template region was cached or not.

If there was some function like $this-phptal-is_cached($id); i  
could check
for example if news section is cached and if so i don't have to load  
database

class, and news model wich takes some time to load.

I hope you understand what i am trying to say.


Is there a way to work this out without hacking PHPTAL classes? With  
triggers
maybe, but i dont want to write a trigger for every template cached  
section.


Dont need the code just an advice maybe :)


There's no way to do that.

I can't imagine clean and simple interface for this (obvious solutions  
break down if you have multiple cached fragments or use macros with  
external templates or non-trivial per expressions). It's also shady  
busines in MVC model when controller is querying views.


However, there's a very good way to use caching effectively without  
querying templates.


Instead of loading classes upfront, pass a proxy object to the  
template, that loads data on demand.


Rather than loading data immediately:

$phptal-var = new ExpensiveData();

make it loaded lazily:

$phptal-varproxy = new Proxy();

class Proxy
{
function getExpensiveData() {
return new ExpensiveData();
}
}

and when you use varproxy/getExpensiveData it will be loaded on demand.

--
regards, Kornel


___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


[PHPTAL] Check if cached

2009-11-10 Thread Andrew

Hello i've got a question and suggestion...

I am using CodeIgniter framework with PHPTAL and it works great, but there is 
little problem with caching. I cant get a nice preformance boost because i 
can't figure out how to check if template region was cached or not. 

If there was some function like $this-phptal-is_cached($id); i could check 
for example if news section is cached and if so i don't have to load database 
class, and news model wich takes some time to load.

I hope you understand what i am trying to say.


Is there a way to work this out without hacking PHPTAL classes? With triggers 
maybe, but i dont want to write a trigger for every template cached section. 

Dont need the code just an advice maybe :)


___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal