cn-uofbasel / ccn-lite

CCN-lite, a lightweight implementation of the CCNx protocol and its variations
ISC License
74 stars 63 forks source link

Enable custom caching decision and cache replacement strategies #373

Closed jpfender closed 4 years ago

jpfender commented 4 years ago

Contribution description

This PR enables users to easily define their own caching decision and cache replacement strategies.

A quick note on terminology:

CCN-lite already provides an interface for user-defined cache replacement strategies using the ccnl_set_cache_strategy_remove() function in ccn-lite-riot.c. However, any user-defined strategies are not actually consulted in ccnl_content_add2cache(), which just applies LRU. This PR moves the relevant functions to ccnl-relay.c to make them accessible everywhere, not just in RIOT, and amends ccnl_content_add2cache() to consult the user-defined caching strategy. If there is no user-defined strategy, the default LRU is applied.

The caching decision strategy is implemented the same way. Use ccnl_set_cache_strategy_cache() to define a caching decision strategy that returns 1 if the content is to be cached and 0 otherwise. This caching decision strategy is consulted in ccnl_fwd_handleContent(). If no user-defined caching strategy exists, 1 is always returned, i.e. the content is always cached, just like before.

These changes do not modify the default behaviour if no user-defined strategies exist.

blacksheeep commented 4 years ago

Thanks, that look like a very nice work and extension.