Commit ca217a18 authored by Karel Slaný's avatar Karel Slaný Committed by Ondřej Surý
Browse files

Cookies can be removed from cache.

parent 6379e459
......@@ -164,6 +164,23 @@ int kr_cookie_cache_insert(struct kr_cache_txn *txn,
return kr_ok();
}
int kr_cookie_cache_remove(struct kr_cache_txn *txn,
uint8_t tag, const void *sockaddr)
{
if (!txn_is_valid(txn) || !sockaddr) {
return kr_error(EINVAL);
}
uint8_t keybuf[KEY_SIZE];
size_t key_len = cache_key(keybuf, tag, sockaddr);
if (key_len == 0) {
return kr_error(EILSEQ);
}
knot_db_val_t key = { keybuf, key_len };
txn->owner->stats.delete += 1;
return txn_api(txn)->del(&txn->t, &key);
}
int kr_cookie_cache_peek_cookie(struct kr_cache_txn *txn, const void *sockaddr,
struct timed_cookie *cookie, uint32_t *timestamp)
{
......
......@@ -51,6 +51,17 @@ int kr_cookie_cache_insert(struct kr_cache_txn *txn,
uint8_t tag, const void *sockaddr,
struct kr_cache_entry *header, knot_db_val_t data);
/**
* Remove asset from cache.
* @param txn transaction instance
* @param tag asset tag
* @param sockaddr asset socket address
* @return 0 or an error code
*/
KR_EXPORT
int kr_cookie_cache_remove(struct kr_cache_txn *txn,
uint8_t tag, const void *sockaddr);
/**
* Structure used for cookie cache interface.
* @note There is no other way how to pass a ttl into a cookie.
......@@ -86,3 +97,6 @@ KR_EXPORT
int kr_cookie_cache_insert_cookie(struct kr_cache_txn *txn, const void *sockaddr,
const struct timed_cookie *cookie,
uint32_t timestamp);
#define kr_cookie_cache_remove_cookie(txn, sockaddr) \
kr_cookie_cache_remove((txn), KR_CACHE_COOKIE, (sockaddr))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment