First of all, I need to mention - this is all theoretical. Thus, there will be no codes. I just need an advice.
OK, Here it is:
I have a Cache class that caches the entities in my game.
Now, I have classes that draw these entities. Thus, they need to get the references for those entities from the cache memory.
The problem is, in my game, some entities come and go. It means that if they leave the screen(scrolled-out or the player shoots at them and kills them), they are out of the game and thus they are removed from the original memory. Each action on entities, whether is creating them or destroying them in also performed on the cache memory. For instance, if I decide to create an entity, a copy of this entity is sent to the cache memory.
Now, because of this, I need, in each frame of the game, to get the updated version of the cache memory. I cannot just get the cache once and that’s it.
So my question is: How can I keep the entities in the drawers classes updated without performing a query to the cache memory every frame?
If it’s impossible then what should I do: perform a query to the cache memory a lot of times or to go straight to the original memory where the actual entities are stored?
I would be really happy if there is a way to keep working with the cache memory, but to me, efficiency comes first
EDIT:
Alright guys I managed to solve this by implementing an Observer pattren. Everytime an entity is gone, the cache class notifies all the observers in the drawers class, managing to keep the the entities that needs to be drawn updated!