Permalink
Browse files

LruCache, feat: not emit the expire event until the event callback fu…

…nction has changed.
  • Loading branch information...
xicilion committed Jul 15, 2018
1 parent a2d5f17 commit 4cd7e718d6f7408edf4a68df6e7a8aa7a4e40a1f
Showing with 9 additions and 1 deletion.
  1. +9 −1 fibjs/include/LruCache.h
View
@@ -35,6 +35,11 @@ class LruCache : public LruCache_base {
public:
// object_base
virtual result_t toJSON(exlib::string key, v8::Local<v8::Value>& retVal);
virtual result_t onEventChange(v8::Local<v8::Function> func, exlib::string ev, exlib::string type)
{
m_has_event = 1;
return 0;
}
EVENT_SUPPORT();
@@ -191,7 +196,9 @@ class LruCache : public LruCache_base {
ei->put("value", GetPrivate(it->first));
Variant v = ei;
_emit("expire", &v, 1);
if(m_has_event)
_emit("expire", &v, 1);
remove(it);
}
@@ -210,6 +217,7 @@ class LruCache : public LruCache_base {
int32_t m_size;
int32_t m_timeout;
date_t m_checkTime;
exlib::atomic m_has_event;
};
} /* namespace fibjs */

0 comments on commit 4cd7e71

Please sign in to comment.