| 55 | bool contains(const key_type& key) { return map_.find(key) != map_.end(); } |
| 56 | |
| 57 | void insert(const key_type& key, const value_type& value) { |
| 58 | typename map_type::iterator i = map_.find(key); |
| 59 | if (i == map_.end()) { |
| 60 | // insert item into the cache, but first check if it is full |
| 61 | if (size() >= cache_capacity_) { |
| 62 | // cache is full, evict the least recently used item |
| 63 | evict(); |
| 64 | } |
| 65 | |
| 66 | // insert the new item |
| 67 | lru_list_.push_front(key); |
| 68 | map_[key] = std::make_pair(value, lru_list_.begin()); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | std::optional<value_type> get(const key_type& key) { |
| 73 | // lookup value in the cache |