All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Classes | Public Types | Public Member Functions | List of all members
ndn::MemoryContentCache Class Reference

A MemoryContentCache holds a set of Data packets and answers an Interest to return the correct Data packet. More...

#include <memory-content-cache.hpp>

Classes

class  Content
 Content is a private class to hold the name and encoding for each entry in the cache. More...
 
class  PendingInterest
 A PendingInterest holds an interest which onInterest received but could not satisfy. More...
 

Public Types

typedef std::vector
< ptr_lib::shared_ptr< const
Content > > 
ContentList
 
typedef func_lib::function
< void(const
ptr_lib::shared_ptr
< ContentList > &contentList)> 
OnContentRemoved
 An OnContentRemoved function object is called when content is removed from the cache. More...
 

Public Member Functions

 MemoryContentCache (Face *face, Milliseconds cleanupIntervalMilliseconds=1000.0)
 Create a new MemoryContentCache to use the given Face. More...
 
void registerPrefix (const Name &prefix, const OnRegisterFailed &onRegisterFailed, const OnInterestCallback &onDataNotFound=OnInterestCallback(), const ForwardingFlags &flags=ForwardingFlags(), WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
 Call registerPrefix on the Face given to the constructor so that this MemoryContentCache will answer interests whose name has the prefix. More...
 
void registerPrefix (const Name &prefix, const OnRegisterFailed &onRegisterFailed, const OnRegisterSuccess &onRegisterSuccess, const OnInterestCallback &onDataNotFound=OnInterestCallback(), const ForwardingFlags &flags=ForwardingFlags(), WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
 Call registerPrefix on the Face given to the constructor so that this MemoryContentCache will answer interests whose name has the prefix. More...
 
void setInterestFilter (const InterestFilter &filter, const OnInterestCallback &onDataNotFound=OnInterestCallback())
 Call setInterestFilter on the Face given to the constructor so that this MemoryContentCache will answer interests whose name matches the filter. More...
 
void setInterestFilter (const Name &prefix, const OnInterestCallback &onDataNotFound=OnInterestCallback())
 Call setInterestFilter on the Face given to the constructor so that this MemoryContentCache will answer interests whose name has the prefix. More...
 
void unregisterAll ()
 Call Face.unsetInterestFilter and Face.removeRegisteredPrefix for all the prefixes given to the setInterestFilter and registerPrefix method on this MemoryContentCache object so that it will not receive interests any more. More...
 
void add (const Data &data)
 Add the Data packet to the cache so that it is available to use to answer interests. More...
 
void storePendingInterest (const ptr_lib::shared_ptr< const Interest > &interest, Face &face)
 Store an interest from an OnInterest callback in the internal pending interest table (normally because there is no Data packet available yet to satisfy the interest). More...
 
const OnInterestCallbackgetStorePendingInterest ()
 Return a callback to use for onDataNotFound in registerPrefix which simply calls storePendingInterest() to store the interest that doesn't match a Data packet. More...
 
void getPendingInterestsForName (const Name &name, std::vector< ptr_lib::shared_ptr< const PendingInterest > > &pendingInterests)
 Remove timed-out pending interests, then for each pending interest which matches according to Interest.matchesName(name), append the PendingInterest entry to the given pendingInterests list. More...
 
void getPendingInterestsWithPrefix (const Name &prefix, std::vector< ptr_lib::shared_ptr< const PendingInterest > > &pendingInterests)
 Remove timed-out pending interests, then for each pending interest which matches according to prefix.isPrefixOf(interest.getName()), append the PendingInterest entry to the given pendingInterests list. More...
 
void setOnContentRemoved (const OnContentRemoved &onContentRemoved)
 Set the OnContentRemoved callback to call when stale content is removed from the cache during cleanup. More...
 
Milliseconds getMinimumCacheLifetime ()
 Get the minimum lifetime before removing stale content from the cache. More...
 
void setMinimumCacheLifetime (Milliseconds minimumCacheLifetime)
 Set the minimum lifetime before removing stale content from the cache which can keep content in the cache longer than the lifetime defined in the meta info. More...
 

Detailed Description

A MemoryContentCache holds a set of Data packets and answers an Interest to return the correct Data packet.

The cache is periodically cleaned up to remove each stale Data packet based on its FreshnessPeriod (if it has one).

Note
This class is an experimental feature. See the API docs for more detail at http://named-data.net/doc/ndn-ccl-api/memory-content-cache.html .

Member Typedef Documentation

typedef func_lib::function<void (const ptr_lib::shared_ptr<ContentList>& contentList)> ndn::MemoryContentCache::OnContentRemoved

An OnContentRemoved function object is called when content is removed from the cache.

See setOnContentRemoved().

Constructor & Destructor Documentation

ndn::MemoryContentCache::MemoryContentCache ( Face face,
Milliseconds  cleanupIntervalMilliseconds = 1000.0 
)
inline

Create a new MemoryContentCache to use the given Face.

Parameters
faceThe Face to use to call registerPrefix and setInterestFilter, and which will call this object's OnInterest callback.
cleanupIntervalMilliseconds(optional) The interval in milliseconds between each check to clean up stale content in the cache. If omitted, use a default of 1000 milliseconds. If this is a large number, then effectively the stale content will not be removed from the cache.

Member Function Documentation

void ndn::MemoryContentCache::add ( const Data data)
inline

Add the Data packet to the cache so that it is available to use to answer interests.

If data.getMetaInfo().getFreshnessPeriod() is not negative, set the staleness time to now plus the maximum of data.getMetaInfo().getFreshnessPeriod() and minimumCacheLifetime, which is checked during cleanup to remove stale content. This also checks if cleanupIntervalMilliseconds milliseconds have passed and removes stale content from the cache. After removing stale content, remove timed-out pending interests from storePendingInterest(), then if the added Data packet satisfies any interest, send it through the transport and remove the interest from the pending interest table. Because this modifies the internal tables, you should call this on the same thread as processEvents, which can also modify the tables.

Parameters
dataThe Data packet object to put in the cache. This copies the fields from the object.
Milliseconds ndn::MemoryContentCache::getMinimumCacheLifetime ( )
inline

Get the minimum lifetime before removing stale content from the cache.

Returns
The minimum cache lifetime in milliseconds.
void ndn::MemoryContentCache::getPendingInterestsForName ( const Name name,
std::vector< ptr_lib::shared_ptr< const PendingInterest > > &  pendingInterests 
)
inline

Remove timed-out pending interests, then for each pending interest which matches according to Interest.matchesName(name), append the PendingInterest entry to the given pendingInterests list.

(To get interests with a given prefix, see getPendingInterestsWithPrefix().) Because this modifies the internal tables, you should call this on the same thread as processEvents, which can also modify the tables.

Parameters
nameThe name to check.
pendingInterestsThe vector to receive the matching PendingInterest objects. This first clears the list before adding objects. You should not modify the PendingInterest objects.
void ndn::MemoryContentCache::getPendingInterestsWithPrefix ( const Name prefix,
std::vector< ptr_lib::shared_ptr< const PendingInterest > > &  pendingInterests 
)
inline

Remove timed-out pending interests, then for each pending interest which matches according to prefix.isPrefixOf(interest.getName()), append the PendingInterest entry to the given pendingInterests list.

Note that interest selectors are ignored. (To get interests which would match a given data packet name, see getPendingInterestsForName().) Because this modifies the internal tables, you should call this on the same thread as processEvents, which can also modify the tables.

Parameters
prefixThe prefix of the interest names to match.
pendingInterestsThe vector to receive the matching PendingInterest objects. This first clears the list before adding objects. You should not modify the PendingInterest objects.
const OnInterestCallback& ndn::MemoryContentCache::getStorePendingInterest ( )
inline

Return a callback to use for onDataNotFound in registerPrefix which simply calls storePendingInterest() to store the interest that doesn't match a Data packet.

add(data) will check if the added Data packet satisfies any pending interest and send it.

Returns
A callback to use for onDataNotFound in registerPrefix().
void ndn::MemoryContentCache::registerPrefix ( const Name prefix,
const OnRegisterFailed onRegisterFailed,
const OnInterestCallback onDataNotFound = OnInterestCallback(),
const ForwardingFlags flags = ForwardingFlags(),
WireFormat wireFormat = *WireFormat::getDefaultWireFormat() 
)
inline

Call registerPrefix on the Face given to the constructor so that this MemoryContentCache will answer interests whose name has the prefix.

Alternatively, if the Face's registerPrefix has already been called, then you can call this object's setInterestFilter.

Parameters
prefixThe Name for the prefix to register. This copies the Name.
onRegisterFailedA function object to call if failed to retrieve the connected hub’s ID or failed to register the prefix. This calls onRegisterFailed(prefix) where prefix is the prefix given to registerPrefix. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.
onDataNotFound(optional) If a data packet for an interest is not found in the cache, this forwards the interest by calling onDataNotFound(prefix, interest, face, interestFilterId, filter). Your callback can find the Data packet for the interest and call face.putData(data). If your callback cannot find the Data packet, it can optionally call storePendingInterest(interest, face) to store the pending interest in this object to be satisfied by a later call to add(data). If you want to automatically store all pending interests, you can simply use getStorePendingInterest() for onDataNotFound. If onDataNotFound is an empty OnInterestCallback(), this does not use it. This copies the function object, so you may need to use func_lib::ref() as appropriate. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.
flags(optional) See Face::registerPrefix.
wireFormat(optional) See Face::registerPrefix.
void ndn::MemoryContentCache::registerPrefix ( const Name prefix,
const OnRegisterFailed onRegisterFailed,
const OnRegisterSuccess onRegisterSuccess,
const OnInterestCallback onDataNotFound = OnInterestCallback(),
const ForwardingFlags flags = ForwardingFlags(),
WireFormat wireFormat = *WireFormat::getDefaultWireFormat() 
)
inline

Call registerPrefix on the Face given to the constructor so that this MemoryContentCache will answer interests whose name has the prefix.

Alternatively, if the Face's registerPrefix has already been called, then you can call this object's setInterestFilter.

Parameters
prefixThe Name for the prefix to register. This copies the Name.
onRegisterFailedA function object to call if failed to retrieve the connected hub’s ID or failed to register the prefix. This calls onRegisterFailed(prefix) where prefix is the prefix given to registerPrefix.
onRegisterSuccess(optional) A function object to call registerPrefix receives a success message from the forwarder. This calls onRegisterSuccess(prefix, registeredPrefixId) where prefix and registeredPrefixId are the values given to registerPrefix. If onRegisterSuccess is an empty OnRegisterSuccess(), this does not use it.
onDataNotFound(optional) If a data packet for an interest is not found in the cache, this forwards the interest by calling onDataNotFound(prefix, interest, face, interestFilterId, filter). Your callback can find the Data packet for the interest and call face.putData(data). If your callback cannot find the Data packet, it can optionally call storePendingInterest(interest, face) to store the pending interest in this object to be satisfied by a later call to add(data). If you want to automatically store all pending interests, you can simply use getStorePendingInterest() for onDataNotFound. If onDataNotFound is an empty OnInterestCallback(), this does not use it. This copies the function object, so you may need to use func_lib::ref() as appropriate.
flags(optional) See Face::registerPrefix.
wireFormat(optional) See Face::registerPrefix.
void ndn::MemoryContentCache::setInterestFilter ( const InterestFilter filter,
const OnInterestCallback onDataNotFound = OnInterestCallback() 
)
inline

Call setInterestFilter on the Face given to the constructor so that this MemoryContentCache will answer interests whose name matches the filter.

Parameters
filterThe InterestFilter with a prefix and optional regex filter used to match the name of an incoming Interest. This makes a copy of filter.
onDataNotFound(optional) If a data packet for an interest is not found in the cache, this forwards the interest by calling onDataNotFound(prefix, interest, face, interestFilterId, filter). Your callback can find the Data packet for the interest and call face.putData(data). Note: If you call setInterestFilter multiple times where filter.getPrefix() is the same, it is undetermined which onDataNotFound will be called. If your callback cannot find the Data packet, it can optionally call storePendingInterest(interest, face) to store the pending interest in this object to be satisfied by a later call to add(data). If you want to automatically store all pending interests, you can simply use getStorePendingInterest() for onDataNotFound. If onDataNotFound is an empty OnInterestCallback(), this does not use it. This copies the function object, so you may need to use func_lib::ref() as appropriate. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.
void ndn::MemoryContentCache::setInterestFilter ( const Name prefix,
const OnInterestCallback onDataNotFound = OnInterestCallback() 
)
inline

Call setInterestFilter on the Face given to the constructor so that this MemoryContentCache will answer interests whose name has the prefix.

Parameters
prefixThe Name prefix used to match the name of an incoming Interest. This copies the Name.
onDataNotFound(optional) If a data packet for an interest is not found in the cache, this forwards the interest by calling onDataNotFound(prefix, interest, face, interestFilterId, filter). Your callback can find the Data packet for the interest and call face.putData(data). If your callback cannot find the Data packet, it can optionally call storePendingInterest(interest, face) to store the pending interest in this object to be satisfied by a later call to add(data). If you want to automatically store all pending interests, you can simply use getStorePendingInterest() for onDataNotFound. If onDataNotFound is an empty OnInterestCallback(), this does not use it. This copies the function object, so you may need to use func_lib::ref() as appropriate. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.
void ndn::MemoryContentCache::setMinimumCacheLifetime ( Milliseconds  minimumCacheLifetime)
inline

Set the minimum lifetime before removing stale content from the cache which can keep content in the cache longer than the lifetime defined in the meta info.

This can be useful for matching interests where MustBeFresh is false. The default minimum cache lifetime is zero, meaning that content is removed when its lifetime expires.

Parameters
minimumCacheLifetimeThe minimum cache lifetime in milliseconds.
void ndn::MemoryContentCache::setOnContentRemoved ( const OnContentRemoved onContentRemoved)
inline

Set the OnContentRemoved callback to call when stale content is removed from the cache during cleanup.

Note: Because onContentRemoved is called while processing incoming Interests, it should return quickly to allow the Interest to be processed quickly.

Parameters
onContentRemovedThis calls onContentRemoved(contentList) where contentList is the list of MemoryContentCache::Content objects that were removed, where each Content has the Name and encoding of the removed content.
void ndn::MemoryContentCache::storePendingInterest ( const ptr_lib::shared_ptr< const Interest > &  interest,
Face face 
)
inline

Store an interest from an OnInterest callback in the internal pending interest table (normally because there is no Data packet available yet to satisfy the interest).

add(data) will check if the added Data packet satisfies any pending interest and send it through the face. Because this modifies the internal tables, you should call this on the same thread as processEvents, which can also modify the tables.

Parameters
interestThe Interest for which we don't have a Data packet yet. You should not modify the interest after calling this.
faceThe Face with the connection which received the interest. This comes from the onInterest callback.
void ndn::MemoryContentCache::unregisterAll ( )
inline

Call Face.unsetInterestFilter and Face.removeRegisteredPrefix for all the prefixes given to the setInterestFilter and registerPrefix method on this MemoryContentCache object so that it will not receive interests any more.

You can call this if you want to "shut down" this MemoryContentCache while your application is still running.


The documentation for this class was generated from the following file: