Page 1 of 1

Caching Classes

Posted: Wed Jul 13, 2005 7:13 pm
by programmermatt
I am participating in a rather large project and am trying to find ways to optimize the scripts. My question is wether it would be smart to set up a server side caching system for classes such as our authentication, permission and user class instead of recreating them every page load (as they use a good amount of queries and logical structures that must recursively process data on creation) ? If so, would it be better to cache via file, DB or something like $_SESSION? How far would such caching be safe and should short or longer expirey times be set? Assuming that there is no way for the wrong cached item to go to the wrong user.

Posted: Wed Jul 13, 2005 7:27 pm
by hawleyjr
I cache classes in sessions all the time:

Code: Select all

$ClassObj= new MyClassIsCoolerThenYourClass($data);

$_SESSION['ClassObj'] = &$ClassObj;

$_SESSION['ClassObj']->getData();

Posted: Wed Jul 13, 2005 7:31 pm
by programmermatt
Yeah, I know how to put objects in $_SESSION, but I am looking for wether it is truly more benificial and for any possible issues that might be caused by the caching, rather than regeneration of classes.

I now realize that this is probably a per-case issue and I should probably run benchmark tests.

Posted: Wed Jul 13, 2005 7:37 pm
by hawleyjr
Generally, if I'll be calling the same class page-to-page I store it in a session. However, very rarely do I have enormous sized classes.

Think about it this way; If you are using the same class every page you're still using the same amount of memory then if you store it in a session var.