GAS暫存資料問題

      在〈GAS暫存資料問題〉中尚無留言

存動態資料,有人會想到用資料庫,客家一點的會使用google excel來充當資料庫

以上方式皆可用,但是用久了,一個問題就會發生

就是 存取速度

資料庫能存大量資料,但每次連線也是需要花時間

google excel,在存取資料,時間就更久了

雖然知道,使用GAS是免費的,但是太慢也會使用起來的體感很差

所以需要一個,速度可行,存量能接受的方式

其實這方法,GAS一直都有!!

PropertiesService

一個在GAS上,能快速存取並有很好的存量的功能
使用起來就與物件一模一樣

function save_data(key,data) {
  var scriptProperties = PropertiesService.getScriptProperties();
  scriptProperties.setProperty(key, data);
  return key+"已存入資料"
}//存資料
function get_data(key)
{
  var scriptProperties = PropertiesService.getScriptProperties();
  var data=scriptProperties.getProperty(key)
  return data
}//取資料
function get_alldata()
{
  var scriptProperties = PropertiesService.getScriptProperties();
  var data=scriptProperties.getProperties()
  return data
}//取全部資料
function delete_alldata()
{
  var scriptProperties = PropertiesService.getScriptProperties();
  scriptProperties.deleteAllProperties()
}//刪全部資料
function delete_data(key)
{
  var scriptProperties = PropertiesService.getScriptProperties();
  scriptProperties.deleteProperty(key)
  return key+"已刪除"
}刪特定資料

有什麼差別呢??

GAS接資料庫,再怎麼快也需要1秒多
接google excel 優化好一點的也要2秒,差的10多秒都有可能
使用PropertiesService呢,存取都在0.2秒以下,差別就是很大。

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *