-
Notifications
You must be signed in to change notification settings - Fork 0
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
Extract thread cache key handling #106
base: main
Are you sure you want to change the base?
Conversation
430365b
to
45b3c71
Compare
45b3c71
to
6badb77
Compare
NOTE: In order to avoid problems with threaded application servers you should always clear the cache key one your | ||
threads once the request is finished using `NxtHttpClient.clear_thread_cache_key` to not have other threads use the | ||
same cache key and thus use cached results across threads. | ||
|
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.
So before a thread could handle a request and then another but keep its cache?
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.
Basically if an application server reuses a thread the thread local variable need to be cleared so it's not bleeding into another request. Because the idea of caching per thread actually is to cache within a single request.
Co-authored-by: Andreas Berg <[email protected]>
Thread.current[THREAD_CACHE_KEY] ||= build_thread_cache_key | ||
end | ||
|
||
def clear_thread_cache_key | ||
Thread.current[THREAD_CACHE_KEY] = nil |
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.
What do you think about using RequestStore gem?
Do we still need this, or can we close the PR? |
Needed for thread cache key clearing for threaded application servers