-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix: 当config.isExpireAfterAccess() 为false时,无需加锁 #952
Open
WangFeiCoder
wants to merge
1
commit into
alibaba:master
Choose a base branch
from
WangFeiCoder:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
这一行得进锁里面去。
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.
放进锁的目的为为了什么呢,当config.isExpireAfterAccess() 为false时,判断逻辑不会走到,加一个锁 仅为了赋值吗。代码中锁加在else 并没没有整个方法,应不会影响其他获取holder对象属性吧。或者是有地方获取holder时加了锁?
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.
对accessTime的读和写必须都在锁内,如果放在锁外,那么对accessTime的写入操作不能保证被别的线程看见。
此外,如果config里面的expireAfterAccess和expireAfterAccessInMillis需要在运行时间动态调整的话,光使用这里这个锁是不管用的,只能实现不严格的最终可见,目前就只打算做到这样。
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.
其实,要增加效率,这个锁就应该去掉,把这些内容放到子类LinkedHashMapCache/CaffeineCache里面去处理,就不用额外加锁了,但是要改涉及到的东西也有点多(放在AbstractEmbeddedCache里面当时主要是想在父类里面统一处理一些逻辑,既然这个逻辑下沉到子类的,其它相关逻辑是不是也要下沉到子类),由于当前定义的InnerMap不能返回错误码,只能用返回null代替,那么最终返回的EXPIRED就会变成NOT_EXISTS,行为略有改变,一些单元测试可能会失败。或者,就要修改InnerMap的定义。