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

About Cache availability mechanism #175

Open
phadtrapong opened this issue Mar 24, 2022 · 2 comments
Open

About Cache availability mechanism #175

phadtrapong opened this issue Mar 24, 2022 · 2 comments
Labels

Comments

@phadtrapong
Copy link

phadtrapong commented Mar 24, 2022

Hi guys,
Does anyone know if currently this library can allow multiple threads to keep read data from cache, while some other threads update cache existing key with new value ?
or multiple threads will be blocked when try to read before new value become available.

@phadtrapong phadtrapong changed the title Question About Cache availability mechanism About Cache availability mechanism Mar 24, 2022
@alastairtree
Copy link
Owner

Sorry for the slow reply. It depends on how you add the new value to the cache. Say you have Version 1 of Item in the cache. Other threads can read Version 1. If you generate Version 2 on another thread outside of LazyCache and then cache the result with CachingService.Add then the update would be almost instant and no thread would be blocked - they just get Version 1 or Version 2 depending on the time of the read.
If you use the expiration to trigger repopulation then threads that read between expiration and regeneration completion would then be blocked, more info at https://github.com/alastairtree/LazyCache/wiki/API-documentation-(v-2.x)#using-immediateexpiration-and-registerpostevictioncallback-to-refresh-a-cached-item-automatically

Hope that helps. Please close the issue if so.

Thanks

@phadtrapong
Copy link
Author

Thank you for your clarification
Small question about expiration trigger, It means item need to be expired first to retrigger or It will be triggered just before data will be thrown away from cache. ( As I understand cahce updated callback will be triggered before item is removed https://docs.microsoft.com/en-us/dotnet/api/system.web.caching.cacheitemupdatecallback?view=netframework-4.8 )

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

No branches or pull requests

2 participants