The Entity class supports the notion of classifications, implemented using Lookups.
Where a Lookup has many LookupRelationships, this can be a major performance hit. E.g a Product might have a species classification, that links to 1000+ breeds.
When selecting products for a particular species, this is particularly noticeable, as the same species classification needs to be retrieved multiple times.
One workaround for this would be to change the Entity class so that it only retrieves the Lookup reference, rather than the entire Lookup. This would require a major refactoring of the code.
A simpler approach is to cache classifications. If the classification being retrieved is cached, then the cached version is returned, otherwise it is pulled in from the database and then cached.
This requires a number of changes:
Entity classifications need to be read-only. Currently its possible to change a classification via the entity, although in practice this is not used
a Lookup cache is required. This would be referred to when retrieving Entity classifications.
the cache needs to be transactional. Lookup changes made within the current transaction are only visible to the current transaction, but are committed to the cache on transaction commit.
the cache needs to be shed data in low memory situations
the cache needs to be cleared if the LookupReplacer is used, as that updates the underlying database