Skip to content

Commit

Permalink
Add CreateCustomGrainDirectoryCache in GrainDirectoryCacheFactory to …
Browse files Browse the repository at this point in the history
…get IGrainDirectoryCache from DI or create the default LRUBasedGrainDirectoryCache.

Update CachedGrainLocator to use GrainDirectoryCacheFactory.CreateCustomGrainDirectoryCache to create inner cache.
  • Loading branch information
mostafa-abdalla authored and ReubenBond committed Mar 1, 2024
1 parent 4bc142d commit 8924cad
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Orleans.Runtime/GrainDirectory/CachedGrainLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<GrainAddress> Lookup(GrainId grainId)
Expand Down
19 changes: 19 additions & 0 deletions src/Orleans.Runtime/GrainDirectory/GrainDirectoryCacheFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ public static IGrainDirectoryCache CreateGrainDirectoryCache(IServiceProvider se
}
}

/// <summary>
/// Creates <see cref="IGrainDirectoryCache"/> from DI or defaults to <see cref="LRUBasedGrainDirectoryCache"/> if no <see cref="IGrainDirectoryCache"/> found in DI.
/// </summary>
/// <param name="services">The services.</param>
/// <param name="options">The options.</param>
/// <returns>The newly created <see cref="IGrainDirectoryCache"/> instance.</returns>
public static IGrainDirectoryCache CreateCustomGrainDirectoryCache(IServiceProvider services, GrainDirectoryOptions options)
{
var grainDirectoryCache = services.GetService<IGrainDirectoryCache>();
if (grainDirectoryCache != null)
{
return grainDirectoryCache;
}
else
{
return new LRUBasedGrainDirectoryCache(options.CacheSize, options.MaximumCacheTTL);
}
}

internal static AdaptiveDirectoryCacheMaintainer CreateGrainDirectoryCacheMaintainer(
LocalGrainDirectory router,
IGrainDirectoryCache cache,
Expand Down

0 comments on commit 8924cad

Please sign in to comment.