Check out these books they have some good stuff on resource caches and resource managers.
1 - Game Engine Architecture (MUST HAVE)
http://www.amazon.com/dp/1568814135/?tag=stackoverfl08-20
2 - Game Coding Complete
http://www.amazon.com/Game-Coding-Complete-Fourth-Edition/dp/1133776574
Them two books should give you the understanding you need to press on.
As for your topic it really all depends on what size and type of game your are making as to how your code resource cache.
If it is a small indie game you most likely can get by with preloading most or if not all your resources into memory at the start depending on how much resources you have. If you can't preload all the resources into memory you would probably break out the preloading to set points in the game (Think loading screen when switching a map or screen).
If you are working on a larger game or have a open world type game you will need to load resources on the fly and you will need a smart resource cache to know when to load something, when to unload something, ect so you avoid as many cache misses as possible.
Your main goal is to avoid reading from the hard drive as much as possible because it is such a VERY SLOW process. If you have to read from the hard drive make sure you grab as much things as you can in that trip. Grabbing 100 resources from the hard drive at once is always better then grabbing 100 resources one at a time over a period of time.
There are so many different ways developers can accomplish this that I won't go into the details but with some research on smart resource caches you should see a few examples of how it can be done.
Does it have to have some knowledge of the current level structure? |
For a smart resource cache yes some games will use the level structure to determine what resources are to be loaded and unloaded into the cache. For example lets say you are playing a FPS that is inside a big building with lots of hallways and different floors.
The resource cache could use the natural layout of the building to determine what sections to load. It would then position certain trigger points in critical areas around the building to send messages to the cache that it can unload these resources and load these. These trigger points would be in hallways, stairways and other points where you could reasonably determine where the character would be heading.
But in reality you really shouldn't have to worry about creating a smart resource cache that knows when to load and unload resources to avoid cache misses unless you are working on a quite serious indie project or a AAA quality game. Though it is a fascinating subject if you are interested in it.