Class: MemoryContentCache

MemoryContentCache

new MemoryContentCache(face, cleanupIntervalMilliseconds)

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).
Parameters:
Name Type Description
face Face The Face to use to call registerPrefix and setInterestFilter, and which will call this object's OnInterest callback.
cleanupIntervalMilliseconds number (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.
Source:

Members

emptyComponent

< elements are MemoryContentCache.StaleTimeContent
Source:

interestFilterIdList

< The map key is the prefix.toUri(). The value is an OnInterest function.
Source:

noStaleTimeCache

< elements are number
Source:

registeredPrefixIdList

< elements are number
Source:

staleTimeCache

< elements are MemoryContentCache.Content
Source:

Methods

(static) Content(data)

Content is a private class to hold the name and encoding for each entry in the cache. This base class is for a Data packet without a FreshnessPeriod. Create a new Content entry to hold data's name and wire encoding.
Parameters:
Name Type Description
data Data The Data packet whose name and wire encoding are copied.
Source:

(static) PendingInterest()

A PendingInterest holds an interest which onInterest received but could not satisfy. When we add a new data packet to the cache, we will also check if it satisfies a pending interest.
Source:

(static) StaleTimeContent(data)

StaleTimeContent extends Content to include the staleTimeMilliseconds for when this entry should be cleaned up from the cache. Create a new StaleTimeContent to hold data's name and wire encoding as well as the staleTimeMilliseconds which is now plus data.getMetaInfo().getFreshnessPeriod().
Parameters:
Name Type Description
data Data The Data packet whose name and wire encoding are copied.
Source:

add(data)

Add the Data packet to the cache so that it is available to use to answer interests. If data.getMetaInfo().getFreshnessPeriod() is not null, set the staleness time to now plus data.getMetaInfo().getFreshnessPeriod(), 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 face and remove the interest from the pending interest table.
Parameters:
Name Type Description
data Data The Data packet object to put in the cache. This copies the fields from the object.
Source:

doCleanup()

Check if now is greater than nextCleanupTime and, if so, remove stale content from staleTimeCache and reset nextCleanupTime based on cleanupIntervalMilliseconds. Since add(Data) does a sorted insert into staleTimeCache, the check for stale data is quick and does not require searching the entire staleTimeCache.
Source:

getStorePendingInterest() → {function}

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.
Source:
Returns:
A callback to use for onDataNotFound in registerPrefix().
Type
function

onInterest()

This is the OnInterest callback which is called when the library receives an interest whose name has the prefix given to registerPrefix. First check if cleanupIntervalMilliseconds milliseconds have passed and remove stale content from the cache. Then search the cache for the Data packet, matching any interest selectors including ChildSelector, and send the Data packet to the face. If no matching Data packet is in the cache, call the callback in onDataNotFoundForPrefix (if defined).
Source:

registerPrefix(prefix, onRegisterFailed, onRegisterSuccess, onDataNotFound, flags, wireFormat)

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:
Name Type Description
prefix Name The Name for the prefix to register. This copies the Name.
onRegisterFailed function If this fails to register the prefix for any reason, 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.
onRegisterSuccess function (optional) When this receives a success message, this calls onRegisterSuccess[0](prefix, registeredPrefixId). If onRegisterSuccess is [null] or omitted, this does not use it. (As a special case, this optional parameter is supplied as an array of one function, instead of just a function, in order to detect when it is used instead of the following optional onDataNotFound function.) 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 function (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 omitted or null, this does not use it. 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 ForwardingFlags (optional) See Face.registerPrefix.
wireFormat WireFormat (optional) See Face.registerPrefix.
Source:

setInterestFilter(filter, prefix, onDataNotFound)

Call setInterestFilter on the Face given to the constructor so that this MemoryContentCache will answer interests whose name matches the filter. There are two forms of setInterestFilter. The first form uses the exact given InterestFilter: setInterestFilter(filter, [onDataNotFound]). The second form creates an InterestFilter from the given prefix Name: setInterestFilter(prefix, [onDataNotFound]).
Parameters:
Name Type Description
filter InterestFilter The InterestFilter with a prefix and optional regex filter used to match the name of an incoming Interest. This makes a copy of filter.
prefix Name The Name prefix used to match the name of an incoming Interest.
onDataNotFound function (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 omitted or null, this does not use it. 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.
Source:

storePendingInterest(interest, 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). add(data) will check if the added Data packet satisfies any pending interest and send it through the face.
Parameters:
Name Type Description
interest Interest The Interest for which we don't have a Data packet yet. You should not modify the interest after calling this.
face Face The Face with the connection which received the interest. This comes from the OnInterest callback.
Source:

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. You can call this if you want to "shut down" this MemoryContentCache while your application is still running.
Source: