Skip to content
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

Introduce MemoryCacheProvider #74

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

stevcooo
Copy link

@stevcooo stevcooo commented Jun 9, 2024

Description
This PR extends the Nager.PublicSuffix to include a MemoryCache option. Due to Azure restrictions that prevent using LocalFileCache, I implemented a MemoryCache to ensure efficient caching within the application.

Changes
I added a new MemoryCache class to handle in-memory caching.
Integrated MemoryCache into the existing caching mechanism, allowing it to be used as an alternative to LocalFileCache.
I updated relevant documentation to reflect the new caching option.
Added unit tests for the MemoryCache to ensure reliability and performance.
Motivation and Context
Azure's restrictions on using LocalFileCache necessitated an alternative caching strategy. The MemoryCache provides a viable solution, enabling caching functionality while complying with Azure's limitations. This improvement will enhance performance and maintain the flexibility of the caching system within the library.

How Has This Been Tested?
Added unit tests specifically for MemoryCache to verify its functionality.
Extended the Program.cs to make a test in a similar fashion as it's done with the LocalFile cache.

@tinohager
Copy link
Member

Does the cache even come into play here? As far as I know, an Azure function only remains in memory for a few minutes. After that, a “cold start” is performed. Here it would be sufficient to define a single tone for the DomainParser.

@stevcooo
Copy link
Author

I see your point about the AzureFunction. Using a memory cache implementation will allow consumers to take full advantage of the dependency injection, the opposite of what will happen in declaring an instance of DomainParser inside of the function.
In our case, we have a huge AzureFunction, that executes every two hours. During each execution, we need to extract the RegistrableDomain for several hundred records. In this case, the memory cache is a nice way to avoid using the default LocalFileSystemCacheProvider.

@milkyjoe90
Copy link
Sponsor

Would another/better option here be to implement DistributedCache, which would allow for in memory or the myriad of other supported caching options like Redis, SQL, Cosmos etc without requiring anything more from the PublicSuffix library itself?

https://learn.microsoft.com/en-us/aspnet/core/performance/caching/distributed?view=aspnetcore-8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants