添加缓存刷新机制
This commit is contained in:
parent
10581cd1f0
commit
b11389ec88
@ -1,6 +1,7 @@
|
|||||||
#include "precompile.h"
|
#include "precompile.h"
|
||||||
|
|
||||||
#include <a8/openssl.h>
|
#include <a8/openssl.h>
|
||||||
|
#include <a8/timer.h>
|
||||||
|
|
||||||
#include "dbengine.h"
|
#include "dbengine.h"
|
||||||
|
|
||||||
@ -280,5 +281,45 @@ void DBHelper::AddCache(
|
|||||||
user_info->mutable_base_data()->set__online(0);
|
user_info->mutable_base_data()->set__online(0);
|
||||||
cache_users_hash[account_id] = user_info;
|
cache_users_hash[account_id] = user_info;
|
||||||
cache_users_list.push_back(user_info);
|
cache_users_list.push_back(user_info);
|
||||||
|
a8::Timer::Instance()->AddDeadLineTimer
|
||||||
|
(
|
||||||
|
1000 * 60 * 5 + rand() % 1000,
|
||||||
|
a8::XParams()
|
||||||
|
.SetSender(account_id),
|
||||||
|
[] (const a8::XParams& param)
|
||||||
|
{
|
||||||
|
DBHelper::Instance()->RemoveCache(param.sender);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DBHelper::RemoveCache(const std::string& account_id)
|
||||||
|
{
|
||||||
|
if (cache_users_hash.size() < 300) {
|
||||||
|
a8::Timer::Instance()->AddDeadLineTimer
|
||||||
|
(
|
||||||
|
1000 * 60 * 5 + rand() % 1000,
|
||||||
|
a8::XParams()
|
||||||
|
.SetSender(account_id),
|
||||||
|
[] (const a8::XParams& param)
|
||||||
|
{
|
||||||
|
DBHelper::Instance()->RemoveCache(param.sender);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto itr = cache_users_hash.find(account_id);
|
||||||
|
if (itr != cache_users_hash.end()) {
|
||||||
|
auto itr2 = std::find(cache_users_list.begin(),
|
||||||
|
cache_users_list.end(),
|
||||||
|
itr->second);
|
||||||
|
if (itr2 != cache_users_list.end()) {
|
||||||
|
cache_users_list.erase(itr2);
|
||||||
|
} else {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
delete itr->second;
|
||||||
|
cache_users_hash.erase(itr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,4 +54,5 @@ private:
|
|||||||
long long user_value3,
|
long long user_value3,
|
||||||
int last_logintime
|
int last_logintime
|
||||||
);
|
);
|
||||||
|
void RemoveCache(const std::string& account_id);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user