Is there a way to create a Sitecore custom cache which exists for the duration of an indexing operation. I would like to store frequently looked up relationships which can be re-used by different computed index field classes to avoid performing the same lookups multiple times. After indexing completes, this cache can be cleared.
That is possible:
indexing:endwith index name that is being worked on.
The handler listening to start event could create a common cache using
registerNewInstance parameter true (share the same cache instance by name solution wide).
- Wherever you need that cache during indexing, it could be recovered the same way.
- The second handler to deal with indexing, will free cache as soon as indexing ends.
Things to be aware of:
A) You might want to enable the logic for a few indexes only (add filter by name clause)
B) Use Sitecore role-driven config to apply it only for the indexing instance
C) Your data is desired to implement
Sitecore.Caching.Interfaces.ISizeTrackable to let Sitecore track memory consumption. Otherwise, it is brute force calculation with little accuracy.