* @brief this function is called by all eviction algorithms * it performs the following logic * * ``` * if obj in cache: * update_metadata * return true * else: * if cache does not have enough space: * evict until it has space to insert * insert the object * return false * ``` * * @param cache * @param req * @return true if cache hit, false if cache miss */
| 221 | * @return true if cache hit, false if cache miss |
| 222 | */ |
| 223 | bool cache_get_base(cache_t *cache, const request_t *req) { |
| 224 | cache->n_req += 1; |
| 225 | |
| 226 | VERBOSE("******* %s req %ld, obj %ld, obj_size %ld, cache size %ld/%ld\n", cache->cache_name, cache->n_req, |
| 227 | req->obj_id, req->obj_size, cache->get_occupied_byte(cache), cache->cache_size); |
| 228 | |
| 229 | cache_obj_t *obj = cache->find(cache, req, true); |
| 230 | bool hit = (obj != NULL); |
| 231 | |
| 232 | if (cache->admissioner && cache->admissioner->update) { |
| 233 | cache->admissioner->update(cache->admissioner, req, cache->cache_size); |
| 234 | } |
| 235 | |
| 236 | if (hit) { |
| 237 | VVERBOSE("req %ld, obj %ld --- cache hit\n", cache->n_req, req->obj_id); |
| 238 | } else if (!cache->can_insert(cache, req)) { |
| 239 | VVERBOSE("req %ld, obj %ld --- cache miss cannot insert\n", cache->n_req, req->obj_id); |
| 240 | } else { |
| 241 | while (cache->get_occupied_byte(cache) + req->obj_size + cache->obj_md_size > cache->cache_size) { |
| 242 | cache->evict(cache, req); |
| 243 | } |
| 244 | cache->insert(cache, req); |
| 245 | } |
| 246 | |
| 247 | if (cache->prefetcher && cache->prefetcher->prefetch) { |
| 248 | cache->prefetcher->prefetch(cache, req); |
| 249 | } |
| 250 | |
| 251 | return hit; |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * @brief this function is called by all caches to |
no test coverage detected