/** * Return an item if it hasn't been marked as expired, lazily expiring * item as-and-when needed */ struct item * item_get(const struct bstring *key) { struct item *it; it = hashtable_get(key->data, key->len, hash_table); if (it == NULL) { log_verb("get it '%.*s' not found", key->len, key->data); return NULL; } log_verb("get it key %.*s val %.*s", key->len, key->data, it->vlen, item_data(it)); if (_item_expired(it)) { log_verb("get it '%.*s' expired and nuked", key->len, key->data); _item_unlink(it); _item_dealloc(&it); return NULL; } log_verb("get it %p of id %"PRIu8, it, it->id); return it; }
static void _item_replace(struct item *it, struct item *nit) { assert(it->magic == ITEM_MAGIC); assert(!item_is_slabbed(it)); assert(nit->magic == ITEM_MAGIC); assert(!item_is_slabbed(nit)); _item_unlink(it); _item_link(nit); }
static void _item_delete(struct item **it) { log_verb("delete it %p of id %"PRIu8, *it, (*it)->id); _item_unlink(*it); _item_dealloc(it); }
static struct item* _item_get(const char *key, uint16_t nkey) { struct item *it; it = assoc_find(key, nkey); if (it == NULL) return NULL; if (it->exptime != 0 && it->exptime <= time_now()) { _item_unlink(it); return NULL; } item_acquire_refcount(it); _item_touch(it); return it; }
void item_delete(struct item *it) { pthread_mutex_lock(&cache_lock); _item_unlink(it); _item_remove(it); pthread_mutex_unlock(&cache_lock); }