Recently when I was writing a plugin, I encountered an interesting caching scenario.
The plugin does two things, function_A and function_B. They both need to retrieve the same entity that is associated with the plugin target entity. Consider the following scenario:
1. function_A is always called. But function_B is only called when certain condition is met.
2. function_A retrieve only certain fields of that same entity (for performance consideration).
3. function_B retrieve all fields of that same entity.
When function_B is actually called, the original result of query from function_A is returned. This means that other fields are returned as null even though there are values in the database.
I had always thought that CRM will cache if the query is exactly the same, but in this scenario, it shows that that may not be the case.