Welcome, Guest. Please login or register.
Did you miss your activation email?
Jul. 04, 2009, 11:39:39 AM
50802 Posts in 11235 Topics by 6001 Members
Latest Member: CocoChanels
News: Share your PRADO experience with other PRADOers by commenting on the QuickStart Tutorial.
 
The PRADO Community » Prado v3.x » Tips, Snippets and Tutorials » Templates in memory - quick guide « previous next »
Pages: [1] Print
Author Topic: Templates in memory - quick guide  (Read 3396 times)
intol
Senior Member
***

Karma: 6
Offline Offline

Posts: 155


View Profile WWW
« on: Dec. 17, 2007, 02:40:43 PM »

Recently, at http://www.eioba.com we were looking for a way to gain some performance. We started to use memory cache (included in eAccelerator).

So why not to keep PRADO templates and configs in memory? It's about 5-8 queries to database cache less, for every page!

Here's how to do it fast:

In your own Cache class add:

Code:
public function setRAM($key,$value,$expire)
{
eaccelerator_put($key,$value,$expire);
}

Code:
public function getRAM($key,$doUnserialize = true)
{
$value = eaccelerator_get($key);
if($value===NULL)
return false;
else
return $value;
}

and now in your default set and get mode:

Code:
protected function getValue($key)
{
if(strpos($key,"prado:")!==FALSE)
{
      return $this->getRAM($key);
}

...
(instructions for standard case)
}

Code:
protected function setValue($key,$value,$expire)
{
if(strpos($key,"prado:")!==FALSE)
{
return $this->setRAM($key,$value,$expire);
}
...
(instructions for standard case)
}

Remember to overload function generateUniqueKey to:

Code:
public function generateUniqueKey($key)
{
return $key;
}
Logged

Kabayan
Platinum Member
****

Karma: 15
Offline Offline

Posts: 781


Save me...please


View Profile WWW
« Reply #1 on: Dec. 17, 2007, 03:32:02 PM »

This is nice!
This works very well with eAccelerator. Have you tried it other accelerators like APC or Memcache with this approach?
Logged
intol
Senior Member
***

Karma: 6
Offline Offline

Posts: 155


View Profile WWW
« Reply #2 on: Dec. 17, 2007, 03:47:04 PM »

There was no reason, so the answer is: no.
Logged

edythor
Junior Member
**

Karma: 0
Offline Offline

Posts: 12



View Profile WWW
« Reply #3 on: Jan. 04, 2008, 10:13:13 PM »


Hi,

intol,  could you show me, how do you keep  templates with the methods setRam y getRam?


thanks!
Logged
intol
Senior Member
***

Karma: 6
Offline Offline

Posts: 155


View Profile WWW
« Reply #4 on: Jan. 08, 2008, 12:02:01 PM »

If you enable caching, PRADO will automatically try to store templates in cache. Then you just need to overwrite functions "get" and "set" in your cache class:

Code:

class yourDefaultCacheClass {

function yourDefaultCacheClassGetFunction
{

if(strpos($key,"prado:")!==FALSE) //here you know, whether it's a template
{
      return $this->getRAM($key);
}

return parent::yourDefaultCacheClassGetFunction(); //for normal function execution

}
}

etc.
Logged

iurijacob
Junior Member
**

Karma: 2
Offline Offline

Posts: 30



View Profile
« Reply #5 on: Sep. 05, 2008, 12:27:09 AM »

Man, this is very interesting! Awesome! Tanks a lot!!!

Maybe we could save the pagestate on RAM too, don´t we? I mean, overloading some methods of TPage or something. It would be very useful too.
Logged

It´s better be ugly but functional than pretty but useless.
intol
Senior Member
***

Karma: 6
Offline Offline

Posts: 155


View Profile WWW
« Reply #6 on: Sep. 14, 2008, 08:19:59 PM »

It's no problem. You can even use ready methods from our code above (savePageState = setCacheValue, loadPageState=getCacheValue) with some small modyfications.
Logged

Pages: [1] Print 
« previous next »
Jump to: