Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-26884

Don't cache Framework.getService results beyond the current request

    XMLWordPrintable

    Details

    • Tags:
    • Upgrade notes:
      Hide

      The cached service are now deleted and replaced par a direct call to Framework.getService(Class) or by injection.

      Show
      The cached service are now deleted and replaced par a direct call to Framework.getService(Class) or by injection.
    • Sprint:
      nxfit 11.1.6
    • Story Points:
      1

      Description

      There's lots of old code caching the result of looking up a service locally, for instance doing:

          protected MyService myService;
      
          protected MyService getMyService() {
              if (myService == null) {
                  myService = Framework.getService(MyService.class);
              }
              return myService;
          }
      

      This is a bad pattern (it's a premature optimization, the lookup is not costly) and in future Nuxeo versions the service implementation may have to change more dynamically (for hot reload or similar reconfiguration uses).

      This kind of code should be changed to a simple direct lookup. The helper method may stay if it helps minimize code changes, but the field-based caching must go.

      Note that caching in some transient builders or similar objects is not a problem (and should probably be done in a constructor then).

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 3 days, 5 hours
                3d 5h