Wednesday, 15 February 2012

php - What are the benefits of caching instances of a class? -


I have an application in which I repeatedly use the same (uppercase) class. Since I use AJAX for that app, I'll always have to create a new object of this class. Someone advised me to cache an example of this class and use it (in a php environment using APC)

What are its benefits? Is it really saving some time?

  $ this-> Ticket_parris = unsolicited (@pc_fet ("ticket")); If (! $ This-> ticket_parris) {$ this-> Ticket_preissance = new ticket_group (); // long time apc_store ("ticket", serialize ($ this-> ticket_preview)); }    

The benefits are actually realized only if you work with a class If there are things that take a lot of time, memory or other resources in the manufacturer of the class (for example: to read an XML sitemap and build a complex data structure to create your navigation.) You can caching Raise it by dashing it.

It is also worth noting that resources (such as database links and such) can not be cached and uncertainty should be restored without the object (Here is where __ sleep and __ wakeup comes in the magic method).

No comments:

Post a Comment