CacheMgr.h 1.7 KB
Newer Older
J
jinhai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

G
groot 已提交
18 19 20
#pragma once

#include "Cache.h"
S
starlord 已提交
21
#include "metrics/Metrics.h"
S
starlord 已提交
22
#include "utils/Log.h"
G
groot 已提交
23

S
starlord 已提交
24
#include <memory>
S
starlord 已提交
25
#include <string>
S
starlord 已提交
26

J
jinhai 已提交
27
namespace milvus {
G
groot 已提交
28 29
namespace cache {

S
starlord 已提交
30
template <typename ItemObj>
G
groot 已提交
31
class CacheMgr {
S
starlord 已提交
32
 public:
S
starlord 已提交
33 34
    virtual uint64_t
    ItemCount() const;
G
groot 已提交
35

S
starlord 已提交
36 37
    virtual bool
    ItemExists(const std::string& key);
G
groot 已提交
38

S
starlord 已提交
39 40
    virtual ItemObj
    GetItem(const std::string& key);
G
groot 已提交
41

S
starlord 已提交
42 43
    virtual void
    InsertItem(const std::string& key, const ItemObj& data);
G
groot 已提交
44

S
starlord 已提交
45 46
    virtual void
    EraseItem(const std::string& key);
G
groot 已提交
47

S
starlord 已提交
48 49
    virtual void
    PrintInfo();
G
groot 已提交
50

S
starlord 已提交
51 52
    virtual void
    ClearCache();
G
groot 已提交
53

S
starlord 已提交
54 55 56 57 58 59
    int64_t
    CacheUsage() const;
    int64_t
    CacheCapacity() const;
    void
    SetCapacity(int64_t capacity);
G
groot 已提交
60

S
starlord 已提交
61
 protected:
G
groot 已提交
62
    CacheMgr();
G
groot 已提交
63
    virtual ~CacheMgr();
G
groot 已提交
64

S
starlord 已提交
65
 protected:
S
starlord 已提交
66
    using CachePtr = std::shared_ptr<Cache<ItemObj>>;
G
groot 已提交
67 68 69
    CachePtr cache_;
};

S
starlord 已提交
70 71
}  // namespace cache
}  // namespace milvus
G
groot 已提交
72

S
starlord 已提交
73
#include "cache/CacheMgr.inl"