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

Add ConcurrentLRUCache #1268

Merged
merged 6 commits into from Nov 18, 2019
Merged

Add ConcurrentLRUCache #1268

merged 6 commits into from Nov 18, 2019

Conversation

dangleptr
Copy link
Contributor

No description provided.

Comment on lines +73 to +78
std::lock_guard<std::mutex> guard(lock_);
auto v = lru_->get(key);
if (v == boost::none) {
return Status::Error();
}
return std::move(v).value();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ask a question,do we need insert it to cache immediate If this key is not exist in cache ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, maybe we need another method putIfAbsent

@dangleptr dangleptr added the ready-for-testing PR: ready for the CI test label Nov 14, 2019
@nebula-community-bot
Copy link
Member

Unit testing passed.

@bright-starry-sky
Copy link
Contributor

LGTM

@bright-starry-sky
Copy link
Contributor

Jenkins go

@nebula-community-bot
Copy link
Member

Unit testing passed.

void clear() {
for (auto i = 0; i < bucketsNum_; i++) {
buckets_[i].clear();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it need buckets_.clear() at here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we call clear, what we want is to clear the content in cache, not destroy the buckets.

@@ -0,0 +1,79 @@
/* Copyright (c) 2018 vesoft inc. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2019 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

std::lock_guard<std::mutex> guard(lock_);
auto v = lru_->get(key);
if (v == boost::none) {
return Status::Error();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Status::Error(folly::stringPrintf("%s not found", key)) . would be better ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will hurt the performance because miss cache is normal in practice.

@nebula-community-bot
Copy link
Member

Unit testing passed.

@nebula-community-bot
Copy link
Member

Unit testing passed.

Copy link
Contributor

@bright-starry-sky bright-starry-sky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, great job!

@nebula-community-bot
Copy link
Member

Unit testing passed.

@dangleptr dangleptr merged commit b0505e6 into vesoft-inc:master Nov 18, 2019
@dangleptr dangleptr deleted the lru branch November 18, 2019 10:43
tong-hao pushed a commit to tong-hao/nebula that referenced this pull request Jun 1, 2021
* Add ConcurrentLRUCache

* Address sky's comments

* update mod

* Add evict for specified key

* Remove dependency on time obj
yixinglu pushed a commit to yixinglu/nebula that referenced this pull request Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-testing PR: ready for the CI test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants