Re: Question on Variable Assignment
- From: Jerry Stuckle <jstucklex@xxxxxxxxxxxxx>
- Date: Sun, 11 Jan 2009 17:36:02 -0500
GS wrote:
"Jerry Stuckle" <jstucklex@xxxxxxxxxxxxx> wrote in message news:gkdhn0$k0t$1@xxxxxxxxxxxxxxxxxxxxxxGS wrote:"Jerry Stuckle" <jstucklex@xxxxxxxxxxxxx> wrote in message news:gkcscn$eup$2@xxxxxxxxxxxxxxxxxxxxxxGS wrote:I have an object, 'name' that has a number of members. The first time a user visits a page that creates 'name', I check the memcache for it's existance. If not in the memcache, I load the object from the db, and store a copy in the memcache. On any subsequent visit, the copy from memcache ($cache) is found and I then copy it into the object.
Essentially, I retrieve $cache, and then set $this to it the following way...
$this->method1 = $cache->method1
$this->method2 = $cache->method2
.
.
.
$this->methodn = $cache->methodn
As I may change these methods, it seems a little cumbersome. I have tried setting $this = $cache, $this =& $cache, but it doesn't work (and I get no error generated, even with error reporting and display set to on in php.ini.
Any quick way to do this, other then setting method values on a one-to-one basis as I am currently doing?
Thanks again!
Why are you even worrying about caching the object? Just load it from the database as necessary.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
Due to the fact that loading this particular object, on creation, contains a large amount of varied data that requires ~10 trips to the db, caching is much much faster. Saves db traffic, reduces user wait times, etc etc.
Contains data which may be obsolete...
If you have an object which requires 10 database requests to fill, you have a major design problem - either in your database or your code. Even my most complex objects have never required that many database calls.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
When the relevent data is updated (~monthly), the object is refreshed in the memcache, so the cached obj is always up-to-date.
The object in question is a name entry ie 'Bill'.
It contains:
db query #1
- meaning, pronunciation, origins, syllables, times viewed, addition date, name rating
db query #2
- similar sounding names
db query #3
- user submitted nicknames
db query #4
- names derived from this name (child names)
db query #5
- names that this name is derived from (parent names)
db query #6
- user comments for this name
db query #7
- popularity of this name in the United States, by year (used to display a chart)
So 7, not 10. I've combined as many queries as possible to the point where I COULD combine a couple more using a more complicated query, but the cost of doing so is more expensive (the more complicated single query takes longer than doing two seperate ones).
The caching is really working quite well honestly, but I did spend countless hours trying to reduce queries...
Still like a lot of unnecessary work to me. If performance is your concern, then with proper design you should be able to do everything in one query.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.
- References:
- Question on Variable Assignment
- From: GS
- Re: Question on Variable Assignment
- From: Jerry Stuckle
- Re: Question on Variable Assignment
- From: GS
- Re: Question on Variable Assignment
- From: Jerry Stuckle
- Re: Question on Variable Assignment
- From: GS
- Question on Variable Assignment
- Prev by Date: Re: Navigating b/w public and secure pages.
- Next by Date: Re: Navigating b/w public and secure pages.
- Previous by thread: Re: Question on Variable Assignment
- Next by thread: Re: Question on Variable Assignment
- Index(es):
Relevant Pages
|