I often have a module that might serve as an interface to a record stored in a database. For example a 'person' object- which might hold vcard data, some info about them in relation to a company- etc.
So internally I have a load mechanism for the data from db.
I store it in the object until a save mechanism is called to commit changes if any, etc. So essentially the data is sort of cached in the object.
This could be done instead, as a direct call to the database. That is.. if you call for the 'person' object's 'name' method.. instead of something like (pseudocode):
You would do something like..sub name { my $self = shift; $self->{name} ||= $self->dbh->prepare('SELECT FROM ... ... $self->{name}; }
So, in essence, we are making calls for everything, every time.sub name { my $self = shift; $self->dbh->prepare('SELECT FROM ... ... $result; }
I would think the lag time would be apocalyptic- and the whole idea abusive to the db server.
Am I wrong? Does anybody have experience fetching and storing data via an api, directly? Without caching stuff in the object.. ?
Seems that it could be more convenient to code this way. Maybe a little more risky?
In reply to not caching to object in code interface to database? by leocharre
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |