Set and read expires as expire interval. Properly copy parameters when an item is found in cache.
git-svn-id: http://yate.null.ro/svn/yate/trunk@4412 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
3bac3fd1dc
commit
b9f97696a9
|
@ -35,7 +35,7 @@
|
||||||
; Database query examples assume a 'lnp' table with the following fields:
|
; Database query examples assume a 'lnp' table with the following fields:
|
||||||
; - id TEXT The called number
|
; - id TEXT The called number
|
||||||
; - routing TEXT Routing number (may be empty)
|
; - routing TEXT Routing number (may be empty)
|
||||||
; - expires NUMERIC Expire time (EPOCH) in seconds
|
; - timeout TIMESTAMP Expire time
|
||||||
|
|
||||||
; enable: boolean: Enable LNP cache
|
; enable: boolean: Enable LNP cache
|
||||||
; Defaults to no
|
; Defaults to no
|
||||||
|
@ -71,19 +71,19 @@
|
||||||
|
|
||||||
; query_loadcache: string: Database query used to load the LNP cache when created
|
; query_loadcache: string: Database query used to load the LNP cache when created
|
||||||
; This parameter is applied on reload
|
; This parameter is applied on reload
|
||||||
;query_loadcache=SELECT * FROM lnp
|
;query_loadcache=SELECT FLOOR(EXTRACT('EPOCH' FROM (timeout - CURRENT_TIMESTAMP))) AS expires,* FROM lnp
|
||||||
|
|
||||||
; query_loaditem: string: Database query used to load an item when created
|
; query_loaditem: string: Database query used to load an item when created
|
||||||
; This parameter is applied on reload
|
; This parameter is applied on reload
|
||||||
;query_loaditem=SELECT * FROM lnp WHERE id='${id}'
|
;query_loaditem=SELECT FLOOR(EXTRACT('EPOCH' FROM (timeout - CURRENT_TIMESTAMP))) AS expires,* FROM lnp WHERE id='${id}'
|
||||||
|
|
||||||
; query_save: string: Database query used to save an item
|
; query_save: string: Database query used to save an item
|
||||||
; This parameter is applied on reload
|
; This parameter is applied on reload
|
||||||
;query_save=INSERT INTO lnp(id,routing,expires) VALUES('${id}','${routing}',${expires})
|
;query_save=INSERT INTO lnp(id,routing,timeout) VALUES('${id}','${routing}',CURRENT_TIMESTAMP + INTERVAL '${expires} s')
|
||||||
|
|
||||||
; query_expire: string: Database query used to expire items
|
; query_expire: string: Database query used to expire items
|
||||||
; This parameter is applied on reload
|
; This parameter is applied on reload
|
||||||
;query_expire=DELETE FROM lnp WHERE expires <= ${time}
|
;query_expire=DELETE FROM lnp WHERE CURRENT_TIMESTAMP >= timeout
|
||||||
|
|
||||||
|
|
||||||
[cnam]
|
[cnam]
|
||||||
|
@ -91,7 +91,7 @@
|
||||||
; Database query examples assume a 'cnam' table with the following fields:
|
; Database query examples assume a 'cnam' table with the following fields:
|
||||||
; - id TEXT The caller number
|
; - id TEXT The caller number
|
||||||
; - callername TEXT Caller's name (may be empty)
|
; - callername TEXT Caller's name (may be empty)
|
||||||
; - expires NUMERIC Expire time (EPOCH) in seconds
|
; - timeout TIMESTAMP Expire time
|
||||||
|
|
||||||
; enable: boolean: Enable CNAM cache
|
; enable: boolean: Enable CNAM cache
|
||||||
; Defaults to no
|
; Defaults to no
|
||||||
|
@ -121,16 +121,16 @@
|
||||||
|
|
||||||
; query_loadcache: string: Database query used to load the CNAM cache when created
|
; query_loadcache: string: Database query used to load the CNAM cache when created
|
||||||
; This parameter is applied on reload
|
; This parameter is applied on reload
|
||||||
;query_loadcache=SELECT * FROM cnam
|
;query_loadcache=SELECT FLOOR(EXTRACT('EPOCH' FROM (timeout - CURRENT_TIMESTAMP))) AS expires,* FROM cnam
|
||||||
|
|
||||||
; query_loaditem: string: Database query used to load an item when created
|
; query_loaditem: string: Database query used to load an item when created
|
||||||
; This parameter is applied on reload
|
; This parameter is applied on reload
|
||||||
;query_loaditem=SELECT * FROM cnam WHERE id='${id}'
|
;query_loaditem=SELECT FLOOR(EXTRACT('EPOCH' FROM (timeout - CURRENT_TIMESTAMP))) AS expires,* FROM cnam WHERE id='${id}'
|
||||||
|
|
||||||
; query_save: string: Database query used to save an item
|
; query_save: string: Database query used to save an item
|
||||||
; This parameter is applied on reload
|
; This parameter is applied on reload
|
||||||
;query_save=INSERT INTO cnam(id,callername,expires) VALUES('${id}','${callername}',${expires})
|
;query_save=INSERT INTO cnam(id,callername,timeout) VALUES('${id}','${callername}',CURRENT_TIMESTAMP + INTERVAL '${expires} s')
|
||||||
|
|
||||||
; query_expire: string: Database query used to expire items
|
; query_expire: string: Database query used to expire items
|
||||||
; This parameter is applied on reload
|
; This parameter is applied on reload
|
||||||
;query_expire=DELETE FROM cnam WHERE expires <= ${time}
|
;query_expire=DELETE FROM cnam WHERE CURRENT_TIMESTAMP >= timeout
|
||||||
|
|
|
@ -83,7 +83,7 @@ public:
|
||||||
// Expire entries
|
// Expire entries
|
||||||
void expire(const Time& time);
|
void expire(const Time& time);
|
||||||
// Copy params from cache item. Return true if found
|
// Copy params from cache item. Return true if found
|
||||||
bool copyParams(const String& id, NamedList& list, const String& copy);
|
bool copyParams(const String& id, NamedList& list, const String* cpParams);
|
||||||
// Add an item to the cache. Remove an existing one
|
// Add an item to the cache. Remove an existing one
|
||||||
// Set dbSave=false when loading from database to avoid saving it again
|
// Set dbSave=false when loading from database to avoid saving it again
|
||||||
void add(const String& id, const NamedList& params, const String* cpParams,
|
void add(const String& id, const NamedList& params, const String* cpParams,
|
||||||
|
@ -277,7 +277,7 @@ Cache::Cache(const String& name, int size, const NamedList& params)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy params from cache item. Return true if found
|
// Copy params from cache item. Return true if found
|
||||||
bool Cache::copyParams(const String& id, NamedList& list, const String& copy)
|
bool Cache::copyParams(const String& id, NamedList& list, const String* cpParams)
|
||||||
{
|
{
|
||||||
lock();
|
lock();
|
||||||
CacheItem* item = find(id);
|
CacheItem* item = find(id);
|
||||||
|
@ -308,7 +308,7 @@ bool Cache::copyParams(const String& id, NamedList& list, const String& copy)
|
||||||
m_name.c_str(),id.c_str(),TelEngine::c_safe(error),this);
|
m_name.c_str(),id.c_str(),TelEngine::c_safe(error),this);
|
||||||
}
|
}
|
||||||
if (item) {
|
if (item) {
|
||||||
list.copyParams(*item,copy);
|
list.copyParams(*item,!cpParams ? m_copyParams : *cpParams);
|
||||||
dumpItem(*this,*item,"found in cache");
|
dumpItem(*this,*item,"found in cache");
|
||||||
}
|
}
|
||||||
unlock();
|
unlock();
|
||||||
|
@ -421,8 +421,19 @@ CacheItem* Cache::addUnsafe(const String& id, const NamedList& params, const Str
|
||||||
if (list)
|
if (list)
|
||||||
list = list->skipNull();
|
list = list->skipNull();
|
||||||
u_int64_t expires = 0;
|
u_int64_t expires = 0;
|
||||||
if (!dbSave)
|
if (!dbSave) {
|
||||||
expires = (u_int64_t)safeValue(params.getIntValue("expires")) * 1000000;
|
String* exp = params.getParam("expires");
|
||||||
|
if (exp) {
|
||||||
|
int tmp = (int)exp->toInteger();
|
||||||
|
if (tmp > 0)
|
||||||
|
expires = Time::now() + tmp * 1000000;
|
||||||
|
else {
|
||||||
|
XDebug(&__plugin,DebugAll,"Cache(%s) item '%s' already expired [%p]",
|
||||||
|
m_name.c_str(),id.c_str(),this);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!expires)
|
if (!expires)
|
||||||
expires = Time::now() + m_cacheTtl;
|
expires = Time::now() + m_cacheTtl;
|
||||||
// Search for insert/add point and existing item
|
// Search for insert/add point and existing item
|
||||||
|
@ -464,7 +475,7 @@ CacheItem* Cache::addUnsafe(const String& id, const NamedList& params, const Str
|
||||||
String query = m_querySave;
|
String query = m_querySave;
|
||||||
NamedList p(*item);
|
NamedList p(*item);
|
||||||
p.setParam("id",item->toString());
|
p.setParam("id",item->toString());
|
||||||
p.setParam("expires",String((unsigned int)(expires / 1000000)));
|
p.setParam("expires",String((unsigned int)(m_cacheTtl / 1000000)));
|
||||||
p.replaceParams(query);
|
p.replaceParams(query);
|
||||||
Message* m = new Message("database");
|
Message* m = new Message("database");
|
||||||
m->addParam("account",m_account);
|
m->addParam("account",m_account);
|
||||||
|
|
Loading…
Reference in New Issue