Hi there.
I have a site that on many pages, creates an object that contains a large amount of data that unfortunately, even after optimization requires several database trips. To combat rising db traffic, I am now using memcache with great success.
In my __construct for this particular object, I have some simple logic:
"in obj__construct, if there is an entry in the server memcache that matches this object, set the current instantiation to it, else, go to db and construct a new object"
Using the above, db traffic is down some 60%, user experience is up, everyone is happy.
But, being a bit of a perfectionist, and trying to re-enforce best coding practices, I am wondering about how I am assigning the cached values to the object.
i.e. I am doing this when the cached obj is discovered
$this->method1 = $cache->method1
$this->method2 = $cache->method2
.
.
.
$this->methodn = $cache->methodn
This is rather inelegant, and as I add remove methods in the future, the possibility that one of the assignments will be missed increases.
I have tried doing the following, but they all fail without throwing any error:
$this = $cache
$this =& $cache
$this = clone $cache
I can do any of the above of course with another var in place of $this, but it seems that maybe due to the special nature of $this you cannot do the above in the obj...
Any ideas? Am I stuck with my manual method assignment? Or is there a more elegant solution that I am simply missing?
Thanks!