I assume it is not Total Commander that is caching the directory structure, or is it?
Probably not. If you have a large number of files, you can see the same effect if you open a command prompt and type something like dir c:\abc.def /s
You aren't likely to have any files with that name, but it takes a lot longer to finish the first time than it would take if you run it a second time immediately after.
It seems like an OS feature to me, or a hard drive cache.
Where and how exactly is it cached then? (ie. By which component's which mechanism, in which structure?)
Windows/NTFS would be caching the items and there will also be a cache in your hard-disk controller.
How do the system know that the cache is up-to-date or not?
Because the only way of writing to the hard-disk is by using routines that know and therefore update or invalidate the cache. For windows the routines are probably the NTFS device driver, whereas for the hard-disk, it is the disk-controller.
If it can be cached entirely, why is it not cached by default?
Because the cache is better used for other things. To cache it by default would mean
Every time the computer starts, it would have to read and store information on every file on your hard-disk regardless of whether it needed it. This can add a few seconds to your startup time. It is also quite common for people to have millions of files, which means the time could be significantly more.
That memory is not available for caching anything else especially the files you are really working on.
What happens if your profile/documents are stored on a server. Do you want the system to wait while it pulls the information on all your files across the network?
Also remember that just because everything can be cached, doesn't mean it should be cached. It can sometimes take longer to access information in an extremely large cache that in a smaller cache, which means that caching too much can actually slow you down. (By this I mean it is slower than when using smaller cache, but it would still be faster than using no cache)
I suppose a disk controller would cache binary data based on last access of "some position" on disk, right? As it should not understand file system structures. Also I expect the HDD cache be relatively smaller and thus the main|"most significant" cache space is somewhere in the kernel memory space, right? – n611x007 – 2013-04-02T13:49:57.410
1Correct. The HDD cache would normally be a lot smaller than windows (it is normally in the order of 16 or 32 Mb), so if you have a million files, the HDD cache would not be big enough to cache them all. But the cache in the disk controller would be more complicated that just remembering stuff at "some position" on the disk, rather it would be caching the most active sectors or blocks, so if the directory you are accessing happens to be stored in a sector/block it had previous cached, it would be able to return it faster. – sgmoore – 2013-04-02T15:00:31.623