milvus/cpp/src/cache/CacheMgr.cpp
yu yunfeng a95b29aa27 add metrics without prometheus
Former-commit-id: e158ea586681abb5ec44bdc9025ec27e3aa21567
2019-05-28 15:06:17 +08:00

124 lines
2.4 KiB
C++

////////////////////////////////////////////////////////////////////////////////
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
// Unauthorized copying of this file, via any medium is strictly prohibited.
// Proprietary and confidential.
////////////////////////////////////////////////////////////////////////////////
#include "CacheMgr.h"
#include "metrics/Metrics.h"
namespace zilliz {
namespace vecwise {
namespace cache {
CacheMgr::CacheMgr() {
}
CacheMgr::~CacheMgr() {
}
uint64_t CacheMgr::ItemCount() const {
if(cache_ == nullptr) {
return 0;
}
return (uint64_t)(cache_->size());
}
bool CacheMgr::ItemExists(const std::string& key) {
if(cache_ == nullptr) {
return false;
}
return cache_->exists(key);
}
DataObjPtr CacheMgr::GetItem(const std::string& key) {
if(cache_ == nullptr) {
return nullptr;
}
server::Metrics::GetInstance().CacheAccessTotalIncrement();
return cache_->get(key);
}
engine::Index_ptr CacheMgr::GetIndex(const std::string& key) {
DataObjPtr obj = GetItem(key);
if(obj != nullptr) {
return obj->data();
}
return nullptr;
}
void CacheMgr::InsertItem(const std::string& key, const DataObjPtr& data) {
if(cache_ == nullptr) {
return;
}
cache_->insert(key, data);
server::Metrics::GetInstance().CacheAccessTotalIncrement();
}
void CacheMgr::InsertItem(const std::string& key, const engine::Index_ptr& index) {
if(cache_ == nullptr) {
return;
}
DataObjPtr obj = std::make_shared<DataObj>(index);
cache_->insert(key, obj);
server::Metrics::GetInstance().CacheAccessTotalIncrement();
}
void CacheMgr::EraseItem(const std::string& key) {
if(cache_ == nullptr) {
return;
}
cache_->erase(key);
server::Metrics::GetInstance().CacheAccessTotalIncrement();
}
void CacheMgr::PrintInfo() {
if(cache_ == nullptr) {
return;
}
cache_->print();
}
void CacheMgr::ClearCache() {
if(cache_ == nullptr) {
return;
}
cache_->clear();
}
int64_t CacheMgr::CacheUsage() const {
if(cache_ == nullptr) {
return 0;
}
return cache_->usage();
}
int64_t CacheMgr::CacheCapacity() const {
if(cache_ == nullptr) {
return 0;
}
return cache_->capacity();
}
void CacheMgr::SetCapacity(int64_t capacity) {
if(cache_ == nullptr) {
return;
}
cache_->set_capacity(capacity);
}
}
}
}