|
APPLICATION CACHE:
Well, the reason is simple: Categories is such
a static notion, and that they are created just once and used over and over
again, we don't need to fetch them from the database each and every single
time. That would be ridiculous! Not to mention it is an insanely unnecessary
load on the database.
That's why the application fetches the category records just once, caches
it, and from then on uses what is in its cache. Application knows nothing
about your direct interference to the database at this point.
A similar problem will show up many times throughout the application. For
instance, in the Company application, there is
a notion, "job class". And currently there exists only two job classes:
"associate" and "temporary". Should we go and fetch those
classes each and every single time? No, they must be cached. Many applications
won't even bother putting such static information into a database. They just
hard-code it into templates! (and impress us to the bone).
What should we do now? Click on LeftNav->Flush. (We must be an admin to
be able to do so, but we already are I assume). Nothing happened. Well, actually,
nothing "visible" happened. However, the application was asked to
flush its cache and it did it! Now we can go and look at the category tree
again as a proof:
Yes, Vegetables are a piece of Hardware!
Lessons learned:
- Anytime you modify the database directly, make sure to flush the application
cache.
- Don't modify the database by hand! (unless of course if you absolutely
know what the heck you are doing).
Finally, as observed, ‘Product' is the root of the category tree. Its parent
is ‘0'. If you need to create new category trees for whatever reason, there
is no mechanism to do that. You should enter a new category record with a
parent Id ‘0' to create a new category tree, (i.e. you should create a new
root) by hand. It goes something like this:
"insert into category values (categoryId,
0, 'name', 'description');"
But, hey, if you are developing new applications and addressing such needs,
you already know that anyway, right?
|