memgraph/transactions/transaction_store.hpp

39 lines
670 B
C++
Raw Normal View History

2015-10-04 15:47:15 +08:00
#ifndef MEMGRAPH_TRANSACTIONS_TRANSACTION_CACHE_HPP
#define MEMGRAPH_TRANSACTIONS_TRANSACTION_CACHE_HPP
#include <map>
#include <memory>
#include "transaction.hpp"
namespace tx
{
template <class id_t>
class TransactionCache
{
public:
Transaction* get(id_t id) const
{
auto it = cache.find(id);
return it != cache.end() ? it->second.get() : nullptr;
2015-10-04 15:47:15 +08:00
}
void put(id_t id, Transaction* transaction)
{
cache.emplace(std::make_pair(id, std::unique_ptr<Transaction>(transaction)));
2015-10-04 15:47:15 +08:00
}
void del(id_t id)
{
cache.erase(id);
}
private:
std::map<id_t, std::unique_ptr<Transaction>> cache;
};
}
#endif