[Issue #2446] Don't open new ResourceResolver
to resolve clientlib categories
#2528
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is a Proof of Concept on how to resolve issue #2446.
The solution outlined in issue #2446 is to pin an open service-user session to the user request so that the service user session does not need to be re-opened multiple times (which is costly). The problem with this solution is that the Sling API included in AEM 6.5.x does not currently support this.
The PR proposes an alternative solution.
This PR builds on the fact that all resource type -> client library category resolution is performed using a service user session.
Since the same service user is used to perform this resolution for every request, the results of this resolution will not differ for different user sessions - therefore the results are suitable to be cached between multiple requests.
To accomplish this, a new service (
ClientLibraryLookupService
) is added.This service performs the client library category resolution, and then uses a simple
HashMap
as a cache.Initial requests to a clean cache may still cause multiple service user session logins during a single user request; however, once the cache is populated, there are no service user session logins at all.
This has an advantage over pinning the service user session to the user request because (with the exception of the first few requests) there are 0 service user sessions created (instead of 1), and additionally the entire logic and repository access associated with the resource type -> client library category resolution is also eliminated and replaced with a simple hashmap lookup - reducing repository access in general.
To ensure that the cache is kept in sync with the repository, the cache is cleared every time a
com/adobe/granite/ui/librarymanager/INVALIDATED
event is issued - which occurs every time a client library is modified, deleted, or added.When this event is issued, the entire cache is invalidated. This is easier than trying to figure out which cache items are no longer valid and selectively clearing just those entries. Changes to the client libraries on a running AEM instance should be infrequent enough that clearing the entire cache will have a negligible performance impact.