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