(Also, I think you should clip the length of the cache array itself as well when you change this.)