NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
in-memory-storage-lru.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
23 
24 namespace ndn {
25 namespace util {
26 
28  : InMemoryStorage(limit)
29 {
30 }
31 
32 InMemoryStorageLru::InMemoryStorageLru(boost::asio::io_service& ioService,
33  size_t limit)
34  : InMemoryStorage(ioService, limit)
35 {
36 }
37 
38 void
40 {
41  BOOST_ASSERT(m_cleanupIndex.size() <= size());
42  InMemoryStorageEntry* ptr = entry;
43  m_cleanupIndex.insert(ptr);
44 }
45 
46 bool
48 {
49  if (!m_cleanupIndex.get<byUsedTime>().empty()) {
50  CleanupIndex::index<byUsedTime>::type::iterator it = m_cleanupIndex.get<byUsedTime>().begin();
51  eraseImpl((*it)->getFullName());
52  m_cleanupIndex.get<byUsedTime>().erase(it);
53  return true;
54  }
55 
56  return false;
57 }
58 
59 void
61 {
62  CleanupIndex::index<byEntity>::type::iterator it = m_cleanupIndex.get<byEntity>().find(entry);
63  if (it != m_cleanupIndex.get<byEntity>().end())
64  m_cleanupIndex.get<byEntity>().erase(it);
65 }
66 
67 void
69 {
70  beforeErase(entry);
71  afterInsert(entry);
72 }
73 
74 } // namespace util
75 } // namespace ndn
Copyright (c) 2011-2015 Regents of the University of California.
shared_ptr< const Data > find(const Interest &interest)
Finds the best match Data for an Interest.
virtual void afterAccess(InMemoryStorageEntry *entry) override
Update the entry when the entry is returned by the find() function, update the last used time accordi...
virtual bool evictItem()=0
Removes one Data packet from in-memory storage based on derived class implemented replacement policy...
void eraseImpl(const Name &name)
deletes in-memory storage entries by the Name with implicit digest.
Table::const_iterator iterator
Definition: cs-internal.hpp:41
virtual void afterInsert(InMemoryStorageEntry *entry) override
Update the entry after a entry is successfully inserted, add it to the cleanupIndex.
InMemoryStorage::const_iterator begin() const
Returns begin iterator of the in-memory storage ordering by name with digest.
Represents in-memory storage.
virtual void beforeErase(InMemoryStorageEntry *entry) override
Update the entry or other data structures before a entry is successfully erased, erase it from the cl...
Represents an in-memory storage entry.
void erase(const Name &prefix, const bool isPrefix=true)
Deletes in-memory storage entry by prefix by default.