/*! * \brief Swaps contents of two caches * * Exchanges the content of the cache with the content of mp, which is another cache object containing elements of the same type and using the same expiration policy. * Sizes may differ. Maximum number of entries may differ too. * * \param <mp> Another cache of the same type as this whose cache is swapped with that of this cache. * * \throw <exception_invalid_policy> Thrown when the policies of the caches to swap are incompatible. * * \see cache::operator= */ void swap ( cache<Key,Data,Policy,Compare,Allocator>& mp ) { write_lock_type l = lock.lockWrite(); _storage.swap(mp._storage); _policy->swap(*mp._policy); std::size_t m=this->_maxEntries; this->_maxEntries=mp._maxEntries; mp._maxEntries=m; this->_currEntries=this->_size(); mp._currEntries=mp.size(); }
void serialize(Serializer& sink, cache<Key, Value, Policy> const& c) { sink << static_cast<uint64_t>(c.capacity()); sink << static_cast<uint64_t>(c.size()); for (auto entry : c) sink << entry.first << entry.second; }