diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/configuration/acl.conf.lua b/resources/install/scripts/app/xml_handler/resources/scripts/configuration/acl.conf.lua index 7df083ec4e..75f6ac42f6 100644 --- a/resources/install/scripts/app/xml_handler/resources/scripts/configuration/acl.conf.lua +++ b/resources/install/scripts/app/xml_handler/resources/scripts/configuration/acl.conf.lua @@ -33,14 +33,21 @@ ]] --get the cache - if (trim(api:execute("module_exists", "mod_memcache")) == "true") then - XML_STRING = trim(api:execute("memcache", "get configuration:acl.conf")); - else - XML_STRING = "-ERR NOT FOUND"; - end + local cache = require "resources.functions.cache" + local acl_cache_key = "configuration:acl.conf" + XML_STRING, err = cache.get(acl_cache_key) --set the cache - if (XML_STRING == "-ERR NOT FOUND") or (XML_STRING == "-ERR CONNECTION FAILURE") then + if not XML_STRING then + --log cache error + if (debug["cache"]) then + freeswitch.consoleLog("warning", "[xml_handler] " .. acl_cache_key .. " can not be get from memcache: " .. tostring(err) .. "\n"); + end + + --log cache error + if (debug["cache"]) then + freeswitch.consoleLog("warning", "[xml_handler] configuration:acl.conf can not be get from memcache: " .. tostring(err) .. "\n"); + end --set a default value if (expire["acl"] == nil) then @@ -115,7 +122,14 @@ dbh:release(); --set the cache - result = trim(api:execute("memcache", "set configuration:acl.conf '"..XML_STRING:gsub("'", "'").."' "..expire["acl"])); + local ok, err = cache.set(acl_cache_key, XML_STRING, expire["acl"]); + if debug["cache"] then + if ok then + freeswitch.consoleLog("notice", "[xml_handler] " .. acl_cache_key .. " stored in memcache\n"); + else + freeswitch.consoleLog("warning", "[xml_handler] " .. acl_cache_key .. " can not be stored in memcache: " .. tostring(err) .. "\n"); + end + end --send the xml to the console if (debug["xml_string"]) then @@ -126,14 +140,11 @@ --send to the console if (debug["cache"]) then - freeswitch.consoleLog("notice", "[xml_handler] configuration:acl.conf source: database\n"); + freeswitch.consoleLog("notice", "[xml_handler] " .. acl_cache_key .. " source: database\n"); end else - --replace the ' back to a single quote - XML_STRING = XML_STRING:gsub("'", "'"); - --send to the console if (debug["cache"]) then - freeswitch.consoleLog("notice", "[xml_handler] configuration:acl.conf source: memcache\n"); + freeswitch.consoleLog("notice", "[xml_handler] " .. acl_cache_key .. " source: memcache\n"); end end --if XML_STRING diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/configuration/callcenter.conf.lua b/resources/install/scripts/app/xml_handler/resources/scripts/configuration/callcenter.conf.lua index 9d043dd074..9afdfa40a0 100644 --- a/resources/install/scripts/app/xml_handler/resources/scripts/configuration/callcenter.conf.lua +++ b/resources/install/scripts/app/xml_handler/resources/scripts/configuration/callcenter.conf.lua @@ -28,15 +28,17 @@ require "resources.functions.format_ringback" --get the cache + local cache = require "resources.functions.cache" hostname = trim(api:execute("switchname", "")); - if (trim(api:execute("module_exists", "mod_memcache")) == "true") then - XML_STRING = trim(api:execute("memcache", "get configuration:callcenter.conf:" .. hostname)); - else - XML_STRING = "-ERR NOT FOUND"; - end + local cc_cache_key = "configuration:callcenter.conf:" .. hostname + XML_STRING, err = cache.get(cc_cache_key) --set the cache - if (XML_STRING == "-ERR NOT FOUND") or (XML_STRING == "-ERR CONNECTION FAILURE") then + if not XML_STRING then + --log cache error + if (debug["cache"]) then + freeswitch.consoleLog("warning", "[xml_handler] " .. cc_cache_key .. " can not be get from memcache: " .. tostring(err) .. "\n"); + end --connect to the database local Database = require "resources.functions.database"; @@ -282,7 +284,14 @@ --freeswitch.consoleLog("notice", "[xml_handler]"..api:execute("eval ${dsn}")); --set the cache - result = trim(api:execute("memcache", "set configuration:callcenter.conf:" .. hostname .." '"..XML_STRING:gsub("'", "'").."' ".."expire['callcenter.conf']")); + local ok, err = cache.set(cc_cache_key, XML_STRING, expire["callcenter"]); + if debug["cache"] then + if ok then + freeswitch.consoleLog("notice", "[xml_handler] " .. cc_cache_key .. " stored in memcache\n"); + else + freeswitch.consoleLog("warning", "[xml_handler] " .. cc_cache_key .. " can not be stored in memcache: " .. tostring(err) .. "\n"); + end + end --send the xml to the console if (debug["xml_string"]) then @@ -293,13 +302,11 @@ --send to the console if (debug["cache"]) then - freeswitch.consoleLog("notice", "[xml_handler] configuration:callcenter.conf:" .. hostname .." source: database\n"); + freeswitch.consoleLog("notice", "[xml_handler] " .. cc_cache_key .. " source: database\n"); end else - --replace the ' back to a single quote - XML_STRING = XML_STRING:gsub("'", "'"); --send to the console if (debug["cache"]) then - freeswitch.consoleLog("notice", "[xml_handler] configuration:callcenter.conf source: memcache\n"); + freeswitch.consoleLog("notice", "[xml_handler] " .. cc_cache_key .. " source: memcache\n"); end end --if XML_STRING diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/configuration/ivr.conf.lua b/resources/install/scripts/app/xml_handler/resources/scripts/configuration/ivr.conf.lua index 6b2bdf37e5..c8aeed4ab4 100644 --- a/resources/install/scripts/app/xml_handler/resources/scripts/configuration/ivr.conf.lua +++ b/resources/install/scripts/app/xml_handler/resources/scripts/configuration/ivr.conf.lua @@ -30,14 +30,17 @@ local log = require "resources.functions.log".ivr_menu --get the cache - if (trim(api:execute("module_exists", "mod_memcache")) == "true") then - XML_STRING = trim(api:execute("memcache", "get configuration:ivr.conf:" .. ivr_menu_uuid)); - else - XML_STRING = "-ERR NOT FOUND"; - end + local cache = require "resources.functions.cache" + local ivr_menu_cache_key = "configuration:ivr.conf:" .. ivr_menu_uuid + XML_STRING, err = cache.get(ivr_menu_cache_key) --set the cache - if (XML_STRING == "-ERR NOT FOUND" or XML_STRING == "-ERR CONNECTION FAILURE") then + if not XML_STRING then + --log cache error + if (debug["cache"]) then + freeswitch.consoleLog("warning", "[xml_handler] " .. ivr_menu_cache_key .. " can not be get from memcache: " .. tostring(err) .. "\n"); + end + --required includes local Database = require "resources.functions.database" local Settings = require "resources.functions.lazy_settings" @@ -268,7 +271,14 @@ --freeswitch.consoleLog("notice", "[xml_handler]"..api:execute("eval ${dsn}")); --set the cache - result = trim(api:execute("memcache", "set configuration:ivr.conf:".. ivr_menu_uuid .." '"..XML_STRING:gsub("'", "'").."' "..expire['ivr'])); + local ok, err = cache.set(ivr_menu_uuid, XML_STRING, expire["ivr"]); + if debug["cache"] then + if ok then + freeswitch.consoleLog("notice", "[xml_handler] " .. ivr_menu_uuid .. " stored in memcache\n"); + else + freeswitch.consoleLog("warning", "[xml_handler] " .. ivr_menu_uuid .. " can not be stored in memcache: " .. tostring(err) .. "\n"); + end + end --send the xml to the console if (debug["xml_string"]) then @@ -279,14 +289,12 @@ --send to the console if (debug["cache"]) then - freeswitch.consoleLog("notice", "[xml_handler] configuration:ivr.conf:" .. ivr_menu_uuid .." source: database\n"); + freeswitch.consoleLog("notice", "[xml_handler] " .. ivr_menu_cache_key .. " source: database\n"); end else - --replace the ' back to a single quote - XML_STRING = XML_STRING:gsub("'", "'"); --send to the console if (debug["cache"]) then - freeswitch.consoleLog("notice", "[xml_handler] configuration:ivr.conf" .. ivr_menu_uuid .." source: memcache\n"); + freeswitch.consoleLog("notice", "[xml_handler] " .. ivr_menu_cache_key .. " source: memcache\n"); end end --if XML_STRING diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/configuration/sofia.conf.lua b/resources/install/scripts/app/xml_handler/resources/scripts/configuration/sofia.conf.lua index b11fe51e6c..2b219342d4 100644 --- a/resources/install/scripts/app/xml_handler/resources/scripts/configuration/sofia.conf.lua +++ b/resources/install/scripts/app/xml_handler/resources/scripts/configuration/sofia.conf.lua @@ -25,15 +25,17 @@ -- POSSIBILITY OF SUCH DAMAGE. --get the cache - hostname = trim(api:execute("switchname", "")); - if (trim(api:execute("module_exists", "mod_memcache")) == "true") then - XML_STRING = trim(api:execute("memcache", "get configuration:sofia.conf:" .. hostname)); - else - XML_STRING = "-ERR NOT FOUND"; - end + local cache = require "resources.functions.cache" + local hostname = trim(api:execute("switchname", "")) + local sofia_cache_key = "configuration:sofia.conf:" .. hostname + XML_STRING, err = cache.get(sofia_cache_key) --set the cache - if (XML_STRING == "-ERR NOT FOUND") or (XML_STRING == "-ERR CONNECTION FAILURE") then + if not XML_STRING then + --log cache error + if (debug["cache"]) then + freeswitch.consoleLog("warning", "[xml_handler] " .. sofia_cache_key .. " can not be get from memcache: " .. tostring(err) .. "\n"); + end --set a default value if (expire["sofia"] == nil) then @@ -296,7 +298,14 @@ dbh:release(); --set the cache - result = trim(api:execute("memcache", "set configuration:sofia.conf:" .. hostname .." '"..XML_STRING:gsub("'", "'").."' "..expire["sofia"])); + local ok, err = cache.set(sofia_cache_key, XML_STRING, expire["sofia"]) + if debug["cache"] then + if ok then + freeswitch.consoleLog("notice", "[xml_handler] " .. sofia_cache_key .. " stored in memcache\n"); + else + freeswitch.consoleLog("warning", "[xml_handler] " .. sofia_cache_key .. " can not be stored in memcache: " .. tostring(err) .. "\n"); + end + end --send the xml to the console if (debug["xml_string"]) then @@ -307,14 +316,11 @@ --send to the console if (debug["cache"]) then - freeswitch.consoleLog("notice", "[xml_handler] configuration:sofia.conf:" .. hostname .." source: database\n"); + freeswitch.consoleLog("notice", "[xml_handler] " .. sofia_cache_key .. " source: database\n"); end else - --replace the ' back to a single quote - XML_STRING = XML_STRING:gsub("'", "'"); - --send to the console if (debug["cache"]) then - freeswitch.consoleLog("notice", "[xml_handler] configuration:sofia.conf source: memcache\n"); + freeswitch.consoleLog("notice", "[xml_handler] " .. sofia_cache_key .. " source: memcache\n"); end end --if XML_STRING