Uploaded image for project: 'Cache Modules'
  1. Cache Modules
  2. MGNLCACHE-69

Implement javax.inject.Provider which injects a @Named cache

    XMLWordPrintable

Details

    • Task
    • Resolution: Won't Fix
    • Neutral
    • None
    • None
    • None
    • None

    Description

      With MGNLCACHE-55, one can cache arbitrary objects (that was already the case, but the API was awkward, and the cache could not be configured), but one still has to :

      public class FooBar {
        private final Cache cache;
        @Inject
        public FooBar(CacheModule cacheModule) {
          // or keep a ref to module and retrieve the cache when needed
          this.cache = cacheModule.getCacheFactory().getCache("foo-cache");
        }
      }
      

      It'd be nice if one could do this instead:

      public class FooBar {
        private final Cache cache;
        @Inject
        public FooBar(@Named("foo-cache") Cache cache) {
          this.cache = cache;
        }
      }
      

      Another approach (or additional) would let one inject an unnamed Cache, and the name would, by convention, be the class name of the injectee.

      package zim.zam;
      
      public class FooBar {
        private final Cache cache;
        @Inject
        public FooBar(Cache cache) {
          assert cache.getName().equals("zim.zam.FooBar");
          this.cache = cache;
        }
      }
      

      Checklists

        Acceptance criteria

        Attachments

          Issue Links

            Activity

              People

                gjoseph Magnolia International
                gjoseph Magnolia International
                Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:

                  Checklists

                    Task DoR