* @brief this function is called by eviction algorithms that use * the hash table to find whether an object is in the cache * * @param cache * @param req * @param update_cache whether to update the cache, * if true, the number of requests increases by 1, * the object size will be updated, * and if the object is expired, it is removed from the cache * @return the found cache_obj_t* or N
| 172 | * @return the found cache_obj_t* or NULL if not found |
| 173 | */ |
| 174 | cache_obj_t *cache_find_base(cache_t *cache, const request_t *req, const bool update_cache) { |
| 175 | cache_obj_t *cache_obj = hashtable_find(cache->hashtable, req); |
| 176 | |
| 177 | // "update_cache = true" means that it is a real user request, use handle_find |
| 178 | // to update prefetcher's state |
| 179 | if (cache->prefetcher && cache->prefetcher->handle_find && update_cache) { |
| 180 | bool hit = (cache_obj != NULL); |
| 181 | cache->prefetcher->handle_find(cache, req, hit); |
| 182 | } |
| 183 | |
| 184 | if (cache_obj != NULL) { |
| 185 | #ifdef SUPPORT_TTL |
| 186 | if (cache_obj->exp_time != 0 && cache_obj->exp_time < req->clock_time) { |
| 187 | if (update_cache) { |
| 188 | cache->remove(cache, cache_obj->obj_id); |
| 189 | } |
| 190 | |
| 191 | cache_obj = NULL; |
| 192 | } |
| 193 | #endif |
| 194 | |
| 195 | if (update_cache) { |
| 196 | cache_obj->misc.next_access_vtime = req->next_access_vtime; |
| 197 | cache_obj->misc.freq += 1; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | return cache_obj; |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * @brief this function is called by all eviction algorithms |
no test coverage detected