diff options
author | Mauro Sardara <msardara@cisco.com> | 2019-02-04 11:06:18 +0100 |
---|---|---|
committer | Alberto Compagno <acompagn+fdio@cisco.com> | 2019-03-05 09:56:19 +0000 |
commit | 6d7704c1b497341fd6dd3c27e3f64d0db062ccc2 (patch) | |
tree | 668c6820653cd84da8474d330d2807a8765f96b5 /libtransport/src/hicn/transport/utils/content_store.cc | |
parent | ca66305af16e2f8d8f271218ea71f132e6c21916 (diff) |
[HICN-11] Rework on transport protocols improving components modularity
Change-Id: I6683ec5b494238dc93591c103d25275e89b9f267
Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'libtransport/src/hicn/transport/utils/content_store.cc')
-rw-r--r-- | libtransport/src/hicn/transport/utils/content_store.cc | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/libtransport/src/hicn/transport/utils/content_store.cc b/libtransport/src/hicn/transport/utils/content_store.cc index 4c7637dad..d48e16daf 100644 --- a/libtransport/src/hicn/transport/utils/content_store.cc +++ b/libtransport/src/hicn/transport/utils/content_store.cc @@ -34,29 +34,29 @@ void ContentStore::insert( std::unique_lock<std::mutex> lock(cs_mutex_); if (TRANSPORT_EXPECT_FALSE(content_store_hash_table_.size() != - lru_list_.size())) { + fifo_list_.size())) { TRANSPORT_LOGW("Inconsistent size!!!!"); TRANSPORT_LOGW("Hash Table: %zu |||| FIFO List: %zu", - content_store_hash_table_.size(), lru_list_.size()); + content_store_hash_table_.size(), fifo_list_.size()); } // Check if the content can be cached if (content_object->getLifetime() > 0) { if (content_store_hash_table_.size() >= max_content_store_size_) { - content_store_hash_table_.erase(lru_list_.back()); - lru_list_.pop_back(); + content_store_hash_table_.erase(fifo_list_.back()); + fifo_list_.pop_back(); } // Insert new item auto it = content_store_hash_table_.find(content_object->getName()); if (it != content_store_hash_table_.end()) { - lru_list_.erase(it->second.second); + fifo_list_.erase(it->second.second); content_store_hash_table_.erase(content_object->getName()); } - lru_list_.push_front(std::cref(content_object->getName())); - auto pos = lru_list_.begin(); + fifo_list_.push_front(std::cref(content_object->getName())); + auto pos = fifo_list_.begin(); content_store_hash_table_[content_object->getName()] = ContentStoreEntry( ObjectTimeEntry(content_object, std::chrono::steady_clock::now()), pos); } @@ -67,13 +67,11 @@ const std::shared_ptr<ContentObject> &ContentStore::find( std::unique_lock<std::mutex> lock(cs_mutex_); auto it = content_store_hash_table_.find(interest.getName()); if (it != content_store_hash_table_.end()) { - // if (std::chrono::duration_cast<std::chrono::milliseconds>( - // std::chrono::steady_clock::now() - it->second.first.second).count() - // < it->second.first.first->getLifetime() || - // it->second.first.first->getLifetime() == - // default_values::never_expire_time) { - return it->second.first.first; - // } + if (std::chrono::duration_cast<std::chrono::milliseconds>( + std::chrono::steady_clock::now() - it->second.first.second) + .count() < it->second.first.first->getLifetime()) { + return it->second.first.first; + } } return empty_reference_; @@ -82,7 +80,7 @@ const std::shared_ptr<ContentObject> &ContentStore::find( void ContentStore::erase(const Name &exact_name) { std::unique_lock<std::mutex> lock(cs_mutex_); auto it = content_store_hash_table_.find(exact_name); - lru_list_.erase(it->second.second); + fifo_list_.erase(it->second.second); content_store_hash_table_.erase(exact_name); } |