The CPU cache

The cache is a very fast memory area, which we find on the PSP processor. In fact, it's the only component which really runs at the processor speed (222 MHz), the other memory areas (as the RAM, or the VRAM) are much slower.
When you read or write data somewhere, there are in fact written in the CPU cache, and not directly in memory. So if you have to reach this information later, they will immediately be sent back by the cache, because it is fast.
Data are accumulated in the cache (64 bytes at once) and when it's full, the older data are cleared from the cache (so written in RAM at this moment) to leave space for the new data.
Generally, this process is transparent: you do not choose which data to put in cache, it takes charge of it itself. You even not have to know that it exists, and everything would be great... if it was as simple as that!

On PSP unfortunaly, the processor is not the only thing that can reach the various components, like RAM. For example, the graphic processor (formally the GE on PSP, Graphic Engine, but that I will call GPU like for the other consoles) also has access to the RAM.
If you want it to draw an image, you just have to write the image in RAM (or in VRAM) and to ask it to draw it. But, because of the cache, it is not possible, because the image is not really in the RAM, but in the CPU cache! Obviously, the GPU has only access to the RAM, not to the CPU cache. If you do that, you will have a corrupt image, because one part of the image is in cache, the other one in RAM (the mask is 32 kB, so only the oldest part of the image will be in RAM, the other one is still in the cache). To avoid this kind of problem, you will have to take out the image from the cache before ask the GPU to draw it. It is also necessary for palettes. For that, we use the following functions:

void oslUncacheImage(OSL_IMAGE *img);

void oslUncachePalette(OSL_PALETTE *pal);

And in a more general way, to take out a bunch of data from the cache:

void oslUncacheData(void *data, size_t size);

But it is necessary to keep in mind that it is an expensive operation in terms of performance, and you musn't use it exept in necessity, because if you remove systematically your data from the cache, you make it useless, and the performances will be worst.

About performances, it is necessary to keep in mind that on PSP, the cache is 32 kB for data and 32 kB for code. For the code, it would be better that your main game loop is less than 32 kB, so it can be completly in cache and will run faster, because there will be needless to read in RAM (which is very slow) and you will get the maximum processor speed. That's why optimizing the code for speed rather than size (by unrolling loops, for example) will maybe have the inverse effect, because even if it is executed more quickly, it makes it bigger, reducing the cache performance. So, try to not trust in benchmarks, because tiny factors can make big differences in the end (for example, moving a function before or after another one in the code can make win or lose 10 in 20% of performance, whereas nothing changed except the order).