add cache classes

Former-commit-id: 3f1545335159443d0b86bacbd6fdecd040f40820
pull/191/head
groot 2019-04-14 14:36:45 +08:00
parent 53617bd8d3
commit 86de13c860
5 changed files with 8 additions and 10 deletions

View File

@ -4,7 +4,7 @@
# Proprietary and confidential. # Proprietary and confidential.
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
AUX_SOURCE_DIRECTORY(./cache cache_files) aux_source_directory(./cache cache_files)
set(vecwise_engine_src set(vecwise_engine_src
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp

View File

@ -15,15 +15,15 @@ CacheMgr::CacheMgr() {
cache_ = std::make_shared<Cache>(16, 1UL<<32); cache_ = std::make_shared<Cache>(16, 1UL<<32);
} }
size_t CacheMgr::ItemCount() const { uint64_t CacheMgr::ItemCount() const {
if(cache_ == nullptr) { if(cache_ == nullptr) {
return 0; return 0;
} }
return cache_->size(); return (uint64_t)(cache_->size());
} }
bool CacheMgr::IsExists(const std::string& key) { bool CacheMgr::ItemExists(const std::string& key) {
if(cache_ == nullptr) { if(cache_ == nullptr) {
return false; return false;
} }

View File

@ -19,9 +19,9 @@ public:
return mgr; return mgr;
} }
size_t ItemCount() const; uint64_t ItemCount() const;
bool IsExists(const std::string& key); bool ItemExists(const std::string& key);
DataObjPtr GetItem(const std::string& key); DataObjPtr GetItem(const std::string& key);

View File

@ -5,9 +5,7 @@
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
include_directories(../../src) include_directories(../../src)
set(cache_srcs aux_source_directory(../../src/cache cache_srcs)
../../src/cache/Cache.cpp
../../src/cache/CacheMgr.cpp)
set(cache_test_src set(cache_test_src
${unittest_srcs} ${unittest_srcs}

View File

@ -32,7 +32,7 @@ TEST(CacheTest, CACHE_TEST) {
cache_mgr.InsertItem(key, MAKE_100MB_DATA); cache_mgr.InsertItem(key, MAKE_100MB_DATA);
cache::DataObjPtr data = cache_mgr.GetItem(key); cache::DataObjPtr data = cache_mgr.GetItem(key);
ASSERT_TRUE(data != nullptr); ASSERT_TRUE(data != nullptr);
ASSERT_TRUE(cache_mgr.IsExists(key)); ASSERT_TRUE(cache_mgr.ItemExists(key));
ASSERT_EQ(data->size(), 100*1024*1024); ASSERT_EQ(data->size(), 100*1024*1024);
cache_mgr.EraseItem(key); cache_mgr.EraseItem(key);