Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2015, Regents of the University of California. |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 4 | * |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 5 | * This file is part of ndn-tools (Named Data Networking Essential Tools). |
| 6 | * See AUTHORS.md for complete list of ndn-tools authors and contributors. |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 7 | * |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 8 | * ndn-tools is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 11 | * |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 12 | * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 15 | * |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 18 | * |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 19 | * @author Yingdi Yu <yingdi@cs.ucla.edu> |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 22 | |
| 23 | #ifndef NDN_TOOLS_PIB_RESPONSE_CACHE_HPP |
| 24 | #define NDN_TOOLS_PIB_RESPONSE_CACHE_HPP |
Yingdi Yu | 77627ab | 2015-07-21 16:13:49 -0700 | [diff] [blame] | 25 | |
| 26 | #include <ndn-cxx/data.hpp> |
| 27 | #include <map> |
| 28 | |
| 29 | |
| 30 | namespace ndn { |
| 31 | namespace pib { |
| 32 | |
| 33 | /** |
| 34 | * @brief ResponseCache is an abstraction of a cache of response made before |
| 35 | * |
| 36 | * ResponseCache is used to reduce the number of PibDb lookup and Data signing |
| 37 | * operations. |
| 38 | * |
| 39 | * Eventually, it should be replaced by a formal application level cache. This |
| 40 | * one is only a temporary module and is used for test. |
| 41 | */ |
| 42 | class ResponseCache : noncopyable |
| 43 | { |
| 44 | public: |
| 45 | ResponseCache(); |
| 46 | |
| 47 | shared_ptr<const Data> |
| 48 | find(const Name& dataName, bool hasVersion = false) const; |
| 49 | |
| 50 | /** |
| 51 | * @brief Insert a data packet into cache |
| 52 | * |
| 53 | * Name of the inserted data must end with a version component |
| 54 | * |
| 55 | * @param data Data to insert. It MUST have been created with make_shared. |
| 56 | */ |
| 57 | void |
| 58 | insert(const Data& data); |
| 59 | |
| 60 | void |
| 61 | erase(const Name& dataNameWithoutVersion); |
| 62 | |
| 63 | void |
| 64 | clear(); |
| 65 | |
| 66 | private: |
| 67 | typedef std::map<Name, shared_ptr<const Data> > Storage; |
| 68 | |
| 69 | Storage m_storage; |
| 70 | }; |
| 71 | |
| 72 | } // namespace ndn |
| 73 | } // namespace pib |
| 74 | |
Yingdi Yu | 0a312e5 | 2015-07-22 13:14:53 -0700 | [diff] [blame] | 75 | #endif // NDN_TOOLS_PIB_RESPONSE_CACHE_HPP |