diff --git a/config.json.example b/config.json.example index 81c552e9..01da8b67 100644 --- a/config.json.example +++ b/config.json.example @@ -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 diff --git a/lib/inc/drogon/CacheMap.h b/lib/inc/drogon/CacheMap.h index 8ba53112..45ee0577 100755 --- a/lib/inc/drogon/CacheMap.h +++ b/lib/inc/drogon/CacheMap.h @@ -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 _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 timeoutCallback=std::function()) { if(timeout>0) diff --git a/lib/src/SharedLibManager.cc b/lib/src/SharedLibManager.cc index 9d5026e9..5fa7e9aa 100755 --- a/lib/src/SharedLibManager.cc +++ b/lib/src/SharedLibManager.cc @@ -30,8 +30,8 @@ static void forEachFileIn(const std::string &path,const std::function 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(); } \ No newline at end of file diff --git a/trantor b/trantor index 5555d02c..c488f2a7 160000 --- a/trantor +++ b/trantor @@ -1 +1 @@ -Subproject commit 5555d02c1a33b8597d35ca56a614d9ecafdc41ca +Subproject commit c488f2a711d77aa972ed0cf7262e0c824410ec59