| 214 | |
| 215 | template <class C> |
| 216 | void |
| 217 | RefCountCachePartition<C>::put(uint64_t key, C *item, int size, time_t expire_time) |
| 218 | { |
| 219 | Metrics::Counter::increment(this->rsb->refcountcache_total_inserts); |
| 220 | size += sizeof(C); |
| 221 | // Remove any colliding entries |
| 222 | this->erase(key); |
| 223 | |
| 224 | // if we are full, and can't make space-- then don't store the item |
| 225 | if (this->is_full() && !this->make_space_for(size)) { |
| 226 | Dbg(dbg_ctl, "partition %d is full-- not storing item key=%" PRIu64, this->part_num, key); |
| 227 | Metrics::Counter::increment(this->rsb->refcountcache_total_failed_inserts); |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | // Create our value-- which has a ref to the `item` |
| 232 | RefCountCacheHashEntry *val = RefCountCacheHashEntry::alloc(); |
| 233 | val->set(item, key, size, expire_time); |
| 234 | |
| 235 | // add expiry_entry to expiry queue, if the expire time is positive (otherwise it means don't expire) |
| 236 | if (expire_time >= 0) { |
| 237 | Dbg(dbg_ctl, "partition %d adding entry with expire_time=%" PRIdMAX, this->part_num, expire_time); |
| 238 | PriorityQueueEntry<RefCountCacheHashEntry *> *expiry_entry = expiryQueueEntry.alloc(); |
| 239 | new (expiry_entry) PriorityQueueEntry<RefCountCacheHashEntry *>(val); |
| 240 | expiry_queue.push(expiry_entry); |
| 241 | val->expiry_entry = expiry_entry; |
| 242 | } |
| 243 | |
| 244 | // add the item to the map |
| 245 | this->item_map.insert(val); |
| 246 | this->size += val->meta.size; |
| 247 | this->items++; |
| 248 | Metrics::Gauge::increment(this->rsb->refcountcache_current_size, static_cast<int64_t>(val->meta.size)); |
| 249 | Metrics::Gauge::increment(this->rsb->refcountcache_current_items); |
| 250 | } |
| 251 | |
| 252 | template <class C> |
| 253 | void |