diff --git a/src/Orleans.Runtime/GrainDirectory/CachedGrainLocator.cs b/src/Orleans.Runtime/GrainDirectory/CachedGrainLocator.cs index ccf18e8322c..c476d002ed7 100644 --- a/src/Orleans.Runtime/GrainDirectory/CachedGrainLocator.cs +++ b/src/Orleans.Runtime/GrainDirectory/CachedGrainLocator.cs @@ -38,7 +38,7 @@ public CachedGrainLocator( { this.grainDirectoryResolver = grainDirectoryResolver; this.clusterMembershipService = clusterMembershipService; - this.cache = GrainDirectoryCacheFactory.CreateGrainDirectoryCache(serviceProvider, grainDirectoryOptions.Value); + this.cache = GrainDirectoryCacheFactory.CreateCustomGrainDirectoryCache(serviceProvider, grainDirectoryOptions.Value); } public async ValueTask Lookup(GrainId grainId) diff --git a/src/Orleans.Runtime/GrainDirectory/GrainDirectoryCacheFactory.cs b/src/Orleans.Runtime/GrainDirectory/GrainDirectoryCacheFactory.cs index e6832ae27ec..297c773c823 100644 --- a/src/Orleans.Runtime/GrainDirectory/GrainDirectoryCacheFactory.cs +++ b/src/Orleans.Runtime/GrainDirectory/GrainDirectoryCacheFactory.cs @@ -36,6 +36,25 @@ public static IGrainDirectoryCache CreateGrainDirectoryCache(IServiceProvider se } } + /// + /// Creates from DI or defaults to if no found in DI. + /// + /// The services. + /// The options. + /// The newly created instance. + public static IGrainDirectoryCache CreateCustomGrainDirectoryCache(IServiceProvider services, GrainDirectoryOptions options) + { + var grainDirectoryCache = services.GetService(); + if (grainDirectoryCache != null) + { + return grainDirectoryCache; + } + else + { + return new LRUBasedGrainDirectoryCache(options.CacheSize, options.MaximumCacheTTL); + } + } + internal static AdaptiveDirectoryCacheMaintainer CreateGrainDirectoryCacheMaintainer( LocalGrainDirectory router, IGrainDirectoryCache cache,