📜  google apps script moment js - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:22.880000             🧑  作者: Mango

代码示例2
var cacheExpire = 3600;
var momentCache = "momentCache";
var momentUrl = "https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment.min.js"

var momentTzCache = "momentTzCache";
var momentTzUrl = "https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.16/moment-timezone-with-data-2012-2022.min.js"

useCachedOrLive(momentCache,momentUrl);
useCachedOrLive(momentTzCache,momentTzUrl);

function useCachedOrLive(cacheToCheck, url){

  var cache = CacheService.getUserCache();
  var cachedData = cache.get(cacheToCheck);
  console.log(cacheToCheck);
  if(cachedData !== null){
    console.log("using cached " + cacheToCheck)
    eval(cachedData);
  }
  else
  {
    console.log("getting live " + cacheToCheck);
    var response = UrlFetchApp.fetch(url).getContentText();
    cache.put(cacheToCheck, response, cacheExpire);
    eval(response);

  }
}