mirror of
https://gitee.com/an-tao/drogon.git
synced 2024-11-30 02:37:57 +08:00
Update trantor
This commit is contained in:
parent
171140938e
commit
36f18875ec
@ -46,10 +46,10 @@
|
||||
//Load_dynamic_views: false by default, when set to true, drogon will
|
||||
//compile and load dynamically "CSP View Files" in directories defined
|
||||
//by "dynamic_views_path"
|
||||
"load_dynamic_views":true,
|
||||
//"load_dynamic_views":true,
|
||||
//dynamic_views_path: if the path isn't prefixed with / or ./,
|
||||
//it will be relative path of document_root path
|
||||
"dynamic_views_path":["./views"],
|
||||
//"dynamic_views_path":["./views"],
|
||||
//log:set log output,drogon output logs to stdout by default
|
||||
"log":{
|
||||
//log_path:log file path,empty by default,in which case,log will output to the stdout
|
||||
|
@ -30,9 +30,11 @@
|
||||
|
||||
|
||||
#define WHEELS_NUM 4
|
||||
#define BUCKET_NUM_PER_WHEEL 100
|
||||
#define BUCKET_NUM_PER_WHEEL 200
|
||||
#define TICK_INTERVAL 1.0
|
||||
|
||||
//Four wheels with 200 buckets per wheel means the cache map can work with
|
||||
//a timeout up to 200^4 seconds,about 50 years;
|
||||
|
||||
namespace drogon
|
||||
{
|
||||
@ -69,6 +71,8 @@ public:
|
||||
/// number of wheels
|
||||
/// @param bucketsNumPerWheel
|
||||
/// buckets number per wheel
|
||||
/// The max delay of the CacheMap is about tickInterval*(bucketsNumPerWheel^wheelsNum) seconds.
|
||||
|
||||
CacheMap(trantor::EventLoop *loop,
|
||||
float tickInterval=TICK_INTERVAL,
|
||||
size_t wheelsNum=WHEELS_NUM,
|
||||
@ -119,6 +123,10 @@ public:
|
||||
std::function<void()> _timeoutCallback;
|
||||
WeakCallbackEntryPtr _weakEntryPtr;
|
||||
}MapValue;
|
||||
|
||||
//If timeout>0,the value will be erased
|
||||
//within the 'timeout' seconds after the last access
|
||||
|
||||
void insert(const T1& key,T2&& value,size_t timeout=0,std::function<void()> timeoutCallback=std::function<void()>())
|
||||
{
|
||||
if(timeout>0)
|
||||
|
@ -30,8 +30,8 @@ static void forEachFileIn(const std::string &path,const std::function<void (cons
|
||||
/* open dirent directory */
|
||||
if((dp = opendir(path.c_str())) == NULL)
|
||||
{
|
||||
perror("opendir:");
|
||||
std::cerr<<"path:"<<path<<std::endl;
|
||||
//perror("opendir:");
|
||||
LOG_ERROR<<"can't open dir,path:"<<path;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -9,10 +9,12 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
trantor::Logger::setLogLevel(trantor::Logger::TRACE);
|
||||
trantor::EventLoopThread loopThread;
|
||||
loopThread.run();
|
||||
|
||||
drogon::CacheMap<std::string,std::string> cache(loopThread.getLoop(),1,3,3);
|
||||
sleep(15);
|
||||
sleep(3);
|
||||
for(int i=0;i<40;i++)
|
||||
{
|
||||
cache.insert(drogon::formattedString("aaa%d",i),"hehe",i,[=](){
|
||||
@ -86,7 +88,6 @@ int main()
|
||||
});
|
||||
thread1.join();
|
||||
|
||||
loopThread.stop();
|
||||
|
||||
getchar();
|
||||
}
|
2
trantor
2
trantor
@ -1 +1 @@
|
||||
Subproject commit 5555d02c1a33b8597d35ca56a614d9ecafdc41ca
|
||||
Subproject commit c488f2a711d77aa972ed0cf7262e0c824410ec59
|
Loading…
Reference in New Issue
Block a user