Leverage Platform.Cache to speed up QueryBuilder SOQL creation #411
Replies: 1 comment 3 replies
-
(I converted this to a Discussion since it's not really an Issue) In my day-job projects, we recently experimented with using Platform Cache to store the resolved SOQL. The primary challenge is coming up with a key for the cache. The key is a tuple that likely factors in the Selector name, the Selector Method, and a subset of the arguments to that method. For example:
The cache key would likely need to be something like Another more difficult challenge is in Production, the use of Field Sets will materially change the SOQL that's generated. The Admin would need to be provided a facility to invalidate the cache any time they changed field sets on your objects. In short, this is a challenge and not something easily handled at the the framework level, IMO. If you have alternative approaches, I'm interested in hearing them. There are other more minor challenges .. i.e. developers would need to be very aware of the use of the cache and make sure to invalidate the cache any time they push changes that might affect the SOQL. But with some training or deciding to disable the cache in developer orgs, you can probably mitigate that one. Separately, the AEP team has some loose ideas written down (privately for now, but will be shared around publicly soon enough) for supporting User Mode in Summer '22 as an optional alternative to the very high overhead way of enforcing CRUD and FLS in QueryFactory today. This native support for CRUD/FLS enforcement will likely obviate the need for the costly Describes that are used in QueryFactory.getFieldPath(). It's our hope and goal to reduce the CPU expense of using 'wide' selectors. Stay tuned on that one. |
Beta Was this translation helpful? Give feedback.
-
I have a production system where the Selector classes and inside them the construction of complex QueryBuilder SOQL queries takes the most of the time.
I thought about using Platform Cache for that and storing the resulting query for later use.
Beta Was this translation helpful? Give feedback.
All reactions