-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use GrainDirectoryCacheFactory to construct a IGrainDirectoryCache #8844
Conversation
@dotnet-policy-service agree |
{ | ||
this.grainDirectoryResolver = grainDirectoryResolver; | ||
this.clusterMembershipService = clusterMembershipService; | ||
this.cache = new LRUBasedGrainDirectoryCache(GrainDirectoryOptions.DEFAULT_CACHE_SIZE, GrainDirectoryOptions.DEFAULT_MAXIMUM_CACHE_TTL); | ||
this.cache = GrainDirectoryCacheFactory.CreateGrainDirectoryCache(serviceProvider, grainDirectoryOptions.Value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that this method can return an AdaptiveGrainDirectoryCache
, that only make sense when the builtin LocalGrainDirectory
is used. It will do weird thing if used here.
But I agree that it would be nicer to be able to inject/customize the cache used here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, how about if I add a new function in GrainDirectoryCacheFactory
to get IGrainDirectoryCache
from DI if there is one or return LRUBasedGrainDirectoryCache
as a default?
this way we keep the current behavior as is but allow injecting custom IGrainDirectoryCache.
something like:
public static IGrainDirectoryCache CreateGrainDirectoryCache(IServiceProvider services, GrainDirectoryOptions options)
{
var grainDirectoryCache = services.GetService<IGrainDirectoryCache>();
if (grainDirectoryCache != null)
{
return grainDirectoryCache;
}
else
{
return new LRUBasedGrainDirectoryCache(options.CacheSize, options.MaximumCacheTTL);
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benjaminpetit any feedback about the above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I was OOF, catching up in things... Yes I think that's better!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benjaminpetit no worries, welcome back 🙂
I have pushed the new GrainDirectoryCacheFactory function, 'Naming things` strikes again but I did my best to come up with a name and added a summary to explain what it should do, please tell me if the name is not clear or if it can be improved 😉
8924cad
to
802ec09
Compare
…stead of hardcoded value.
…get IGrainDirectoryCache from DI or create the default LRUBasedGrainDirectoryCache. Update CachedGrainLocator to use GrainDirectoryCacheFactory.CreateCustomGrainDirectoryCache to create inner cache.
src/Orleans.Runtime/GrainDirectory/GrainDirectoryCacheFactory.cs
Outdated
Show resolved
Hide resolved
…otnet#8844) --------- Co-authored-by: Mostafa Abdalla <mostafa.abdalla@cm.com> Co-authored-by: Reuben Bond <203839+ReubenBond@users.noreply.github.com> (cherry picked from commit ab644bf)
use GrainDirectoryCacheFactory to construct a IGrainDirectoryCache instead of hardcoded value.
#8843
Microsoft Reviewers: Open in CodeFlow