blob: 94ecfbb4a403e7be5144cb74fa72d552879a3cc9 [file] [log] [blame]
Yingdi Yu77627ab2015-07-21 16:13:49 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yingdi Yu0a312e52015-07-22 13:14:53 -07003 * Copyright (c) 2014-2015, Regents of the University of California.
Yingdi Yu77627ab2015-07-21 16:13:49 -07004 *
Yingdi Yu0a312e52015-07-22 13:14:53 -07005 * 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 Yu77627ab2015-07-21 16:13:49 -07007 *
Yingdi Yu0a312e52015-07-22 13:14:53 -07008 * 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 Yu77627ab2015-07-21 16:13:49 -070011 *
Yingdi Yu0a312e52015-07-22 13:14:53 -070012 * 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 Yu77627ab2015-07-21 16:13:49 -070015 *
Yingdi Yu0a312e52015-07-22 13:14:53 -070016 * 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 Yu77627ab2015-07-21 16:13:49 -070018 *
Yingdi Yu0a312e52015-07-22 13:14:53 -070019 * @author Yingdi Yu <yingdi@cs.ucla.edu>
Yingdi Yu77627ab2015-07-21 16:13:49 -070020 */
21
Yingdi Yu0a312e52015-07-22 13:14:53 -070022
23#ifndef NDN_TOOLS_PIB_RESPONSE_CACHE_HPP
24#define NDN_TOOLS_PIB_RESPONSE_CACHE_HPP
Yingdi Yu77627ab2015-07-21 16:13:49 -070025
26#include <ndn-cxx/data.hpp>
27#include <map>
28
29
30namespace ndn {
31namespace 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 */
42class ResponseCache : noncopyable
43{
44public:
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
66private:
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 Yu0a312e52015-07-22 13:14:53 -070075#endif // NDN_TOOLS_PIB_RESPONSE_CACHE_HPP