| 151 | template <typename KeyType, typename ValueType> |
| 152 | template <typename... Args> |
| 153 | auto LruMultiCache<KeyType, ValueType>::EmplaceAndGet(const KeyType& key, Args&&... args) |
| 154 | -> Accessor { |
| 155 | std::lock_guard<SpinLock> g(lock_); |
| 156 | |
| 157 | // creates default container if there isn't one |
| 158 | Container& container = hash_table_[key]; |
| 159 | |
| 160 | // Get the reference of the key stored in unordered_map, the parameter could be |
| 161 | // temporary object but std::unordered_map has stable references |
| 162 | const KeyType& stored_key = hash_table_.find(key)->first; |
| 163 | |
| 164 | // Place it as the last entry for the owning list, as it just got reserved |
| 165 | auto container_it = container.emplace( |
| 166 | container.end(), (*this), stored_key, container, std::forward<Args>(args)...); |
| 167 | |
| 168 | // Only can set this after emplace |
| 169 | container_it->it = container_it; |
| 170 | |
| 171 | size_++; |
| 172 | |
| 173 | // Need to remove the oldest available if the cache is over the capacity |
| 174 | EvictOneIfNeeded(); |
| 175 | |
| 176 | return Accessor(&(*container_it)); |
| 177 | } |
| 178 | |
| 179 | template <typename KeyType, typename ValueType> |
| 180 | void LruMultiCache<KeyType, ValueType>::Release(ValueType_internal* p_value_internal) { |