NCBI C++ ToolKit
split_info_cache.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef SPLIT_INFO_CACHE__HPP
2 #define SPLIT_INFO_CACHE__HPP
3 
4 /* $Id: split_info_cache.hpp 100918 2023-09-29 15:56:54Z satskyse $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Sergey Satskiy
30  *
31  * File Description:
32  *
33  */
34 
35 
36 #include <mutex>
37 #include <map>
38 #include <list>
39 #include <optional>
40 using namespace std;
41 
42 #include "pubseq_gateway_types.hpp"
43 #include "cass_blob_id.hpp"
44 #include "split_info_utils.hpp"
46 
48 
49 using namespace ncbi::objects;
50 
52 {
53  public:
55  m_LastTouch(psg_clock_t::now()),
56  m_SplitInfoBlob(blob)
57  {}
58 
60  {}
61 
63  {}
64 
65  public:
66  // For the future - if the cache needs to be purged
69 };
70 
71 
72 
74 {
75  public:
76  CSplitInfoCache(size_t high_mark, size_t low_mark) :
77  m_HighMark(high_mark), m_LowMark(low_mark)
78  {}
79 
81  {}
82 
83  public:
84  optional<CRef<CID2S_Split_Info>>
85  GetBlob(const SCass_BlobId & info_blob_id);
86  void AddBlob(const SCass_BlobId & info_blob_id,
88 
89  size_t Size(void)
90  {
91  size_t size = 0;
92  lock_guard<mutex> guard(m_Lock);
93 
94  size = m_Cache.size();
95  return size;
96  }
97 
98  // Cleans up the cache if needed
99  void Maintain(void);
100 
101  private:
102  size_t m_HighMark;
103  size_t m_LowMark;
104  map<SCass_BlobId, SSplitInfoCacheItem> m_Cache;
105  list<SCass_BlobId> m_LRU;
106  mutex m_Lock;
107 };
108 
109 
110 #endif
list< SCass_BlobId > m_LRU
CSplitInfoCache(size_t high_mark, size_t low_mark)
map< SCass_BlobId, SSplitInfoCacheItem > m_Cache
const struct ncbi::grid::netcache::search::fields::SIZE size
chrono::steady_clock psg_clock_t
psg_clock_t::time_point psg_time_point_t
USING_NCBI_SCOPE
psg_time_point_t m_LastTouch
CRef< CID2S_Split_Info > m_SplitInfoBlob
SSplitInfoCacheItem(CRef< CID2S_Split_Info > blob)
Modified on Sat Apr 20 12:22:37 2024 by modify_doxy.py rev. 669887