A cache implementation for nanocoap response messages.
More...
A cache implementation for nanocoap response messages.
|
static void | nanocoap_cache_init (void) |
| Initializes the internal state of the nanocoap cache. More...
|
|
size_t | nanocoap_cache_used_count (void) |
| Returns the number of cached entries. More...
|
|
size_t | nanocoap_cache_free_count (void) |
| Returns the number of unused cache entries. More...
|
|
nanocoap_cache_entry_t * | nanocoap_cache_process (const uint8_t *cache_key, unsigned request_method, const coap_pkt_t *resp, size_t resp_len) |
| Determines if a response is cacheable and modifies the cache as reflected in RFC7252, Section 5.9. More...
|
|
nanocoap_cache_entry_t * | nanocoap_cache_add_by_req (const coap_pkt_t *req, const coap_pkt_t *resp, size_t resp_len) |
| Creates a new or gets an existing cache entry using the request packet. More...
|
|
nanocoap_cache_entry_t * | nanocoap_cache_add_by_key (const uint8_t *cache_key, unsigned request_method, const coap_pkt_t *resp, size_t resp_len) |
| Creates a new or gets an existing cache entry using the cache key. More...
|
|
nanocoap_cache_entry_t * | nanocoap_cache_request_lookup (const coap_pkt_t *req) |
| Performs a cache lookup based on the req . More...
|
|
nanocoap_cache_entry_t * | nanocoap_cache_key_lookup (const uint8_t *cache_key) |
| Performs a cache lookup based on the cache key of a request. More...
|
|
int | nanocoap_cache_del (const nanocoap_cache_entry_t *ce) |
| Deletes the provided cache entry ce . More...
|
|
void | nanocoap_cache_key_generate (const coap_pkt_t *req, uint8_t *cache_key) |
| Generates a cache key based on the request req . More...
|
|
ssize_t | nanocoap_cache_key_compare (uint8_t *cache_key1, uint8_t *cache_key2) |
| Compares two cache keys. More...
|
|
static bool | nanocoap_cache_entry_is_stale (const nanocoap_cache_entry_t *ce, uint32_t now) |
| Check if the Max-Age of a cache entry has passed. More...
|
|
◆ CONFIG_NANOCOAP_CACHE_ENTRIES
#define CONFIG_NANOCOAP_CACHE_ENTRIES (8) |
The number of maximum cache entries.
Definition at line 41 of file cache.h.
◆ CONFIG_NANOCOAP_CACHE_KEY_LENGTH
#define CONFIG_NANOCOAP_CACHE_KEY_LENGTH (8) |
The length of the cache key in bytes.
Definition at line 48 of file cache.h.
◆ CONFIG_NANOCOAP_CACHE_RESPONSE_SIZE
#define CONFIG_NANOCOAP_CACHE_RESPONSE_SIZE (128) |
Size of the buffer to store responses in the cache.
Definition at line 55 of file cache.h.
◆ nanocoap_cache_replacement_strategy_t
typedef int(* nanocoap_cache_replacement_strategy_t) (void) |
Typedef for the cache replacement strategy on full cache list.
- Returns
- 0 on successfully replacing a cache element
-
-1 on error
Definition at line 102 of file cache.h.
◆ nanocoap_cache_update_strategy_t
typedef int(* nanocoap_cache_update_strategy_t) (clist_node_t *node) |
Typedef for the cache update strategy on element access.
- Parameters
-
[in] | node | The accessed node. |
- Returns
- 0 on successfully updating the element
-
-1 on error
Definition at line 112 of file cache.h.
◆ nanocoap_cache_add_by_key()
Creates a new or gets an existing cache entry using the cache key.
- Parameters
-
[in] | cache_key | The cache key of the request |
[in] | request_method | The method of the initial request |
[in] | resp | The response to add to the cache |
[in] | resp_len | The actual length of the response in resp |
- Returns
- The previously existing or newly added cache entry on success
-
NULL, if there is no space left
◆ nanocoap_cache_add_by_req()
Creates a new or gets an existing cache entry using the request packet.
- Parameters
-
[in] | req | The request to calculate the cache-key |
[in] | resp | The response to add to the cache |
[in] | resp_len | The actual length of the response message in resp |
- Returns
- The previously existing or newly added cache entry on success
-
NULL, if there is no space left
◆ nanocoap_cache_del()
Deletes the provided cache entry ce
.
- Parameters
-
[in] | ce | The cache entry to delete |
- Returns
- 0 on success
-
-1 if entry is not available in the cache
◆ nanocoap_cache_entry_is_stale()
Check if the Max-Age of a cache entry has passed.
- Parameters
-
[in] | ce | A cache entry |
[in] | now | The current time |
- Returns
- true, if Max-Age of cache entry has passed.
-
false, if Max-Age of cache entry has not yet passed.
Definition at line 243 of file cache.h.
◆ nanocoap_cache_free_count()
size_t nanocoap_cache_free_count |
( |
void |
| ) |
|
Returns the number of unused cache entries.
- Returns
- Number of unused cache entries
◆ nanocoap_cache_init()
static void nanocoap_cache_init |
( |
void |
| ) |
|
|
inlinestatic |
Initializes the internal state of the nanocoap cache.
Definition at line 120 of file cache.h.
◆ nanocoap_cache_key_compare()
ssize_t nanocoap_cache_key_compare |
( |
uint8_t * |
cache_key1, |
|
|
uint8_t * |
cache_key2 |
|
) |
| |
Compares two cache keys.
- Parameters
-
[in] | cache_key1 | The first cache key in the comparison |
[in] | cache_key2 | The second cache key in the comparison |
- Returns
- 0 if cache keys are equal
-
<0 or 0> (see memcmp()) for unequal cache keys
◆ nanocoap_cache_key_generate()
void nanocoap_cache_key_generate |
( |
const coap_pkt_t * |
req, |
|
|
uint8_t * |
cache_key |
|
) |
| |
Generates a cache key based on the request req
.
- Parameters
-
[in] | req | The request to generate the cache key from |
[out] | cache_key | The generated cache key |
◆ nanocoap_cache_key_lookup()
Performs a cache lookup based on the cache key of a request.
- Parameters
-
[in] | cache_key | The cache key of a request |
- Returns
- An existing cache entry on cache hit
-
NULL on cache miss
◆ nanocoap_cache_process()
Determines if a response is cacheable and modifies the cache as reflected in RFC7252, Section 5.9.
- Parameters
-
[in] | cache_key | The cache key of the request |
[in] | request_method | The method of the initial request |
[in] | resp | The response to operate on |
[in] | resp_len | The actual length of the response in resp |
- Returns
- The cache entry on successfully handling the response
-
NULL on error
◆ nanocoap_cache_request_lookup()
Performs a cache lookup based on the req
.
- Parameters
-
[in] | req | The request to calculate the cache-key |
- Returns
- An existing cache entry on cache hit
-
NULL on cache miss
◆ nanocoap_cache_used_count()
size_t nanocoap_cache_used_count |
( |
void |
| ) |
|
Returns the number of cached entries.
- Returns
- Number of cached entries