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);
|
2015-10-08 06:58:29 +08:00
|
|
|
return it != cache.end() ? it->second.get() : nullptr;
|
2015-10-04 15:47:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void put(id_t id, Transaction* transaction)
|
|
|
|
{
|
2015-10-08 06:58:29 +08:00
|
|
|
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
|