-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nanocoap: cache for CoAP responses #13889
Conversation
rebased to master and dropped the commit that was merged in #13893 |
The cache implementation now integrates into the forward proxy code back in #13790, instead of in |
the last two commits add kconfig configurations for cache related parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please squash!
Seems @cgundogan still has some cleaning up to do, that I missed.
|
||
/* the absolute time of max-age should be at approx. now + 30 sec | ||
(1 sec buffer) */ | ||
now = xtimer_now_usec(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and below (and the unittest's Makefile)
now = xtimer_now_usec(); | |
now = ztimer_now(ZTIMER_SEC); |
no? There is no relation between xtimer_now_usec()
(or ztimer_now(ZTIMER_USEC)
for that matter) to ztimer_now(ZTIMER_SEC)
and the latter is used internally to the cache... so comparing two timers who have no common time basis, is non-sensical in the tests (and might even lead to spurious failures).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2282ee9
to
fdafd37
Compare
Please squash. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments are now addressed. ACK!
@cgundogan was faster ^^ |
Amended a fix for a minor signedness issue. Re-running murdock. |
Contribution description
This PR adds a cache for CoAP response messages to
nanocoap
. RFC7252, Section-5.6 elaborates on the internals of a cache implementation.The basic idea is to reduce response time and enhance bandwidth usage by storing CoAP responses at intermediary proxy nodes. The cache key is calculated using the information in RFC7252, Section 5.10. Optimized cache key calculations based on other mechanisms (e.g., using the ETAG) are not included in this PR (and firstly require a proper cache<->proxy integration).
This proposed implementation uses a simple LRU strategy to replace cache entries as soon as the available cache space is used up. The replacement strategy is passed as a function pointer, so that we can easily add more sophisticated strategies in the future, if needed.
The demonstrated integration intogcoap
is preliminary .. depending on the direction we take in #13790, the included changes togcoap
may change.The cache implementation now integrates into the forward proxy in #13790.
Testing procedure
gcoap
examples, where one of them usesUSEMODULE=nanocoap_cache
nanocoap_cache
module, type0
. The caching node (our fictitious proxy) caches the generated response.3. on the same node, type
0
, because the caching node does not invoke the request handler function, but performs a cache lookup.4. After 60 seconds, repeat the above
get
request, and the response should now contain1
.The default
max-age
(see RFC7252, Section 5.10.5) is 60 seconds, if no explicitmax-age options
are used.Issues/PRs references
depends on #13893depends #13790