How to flush the cache

前端 未结 2 872
野性不改
野性不改 2021-01-15 06:06

In Apps Script I need a way to flush the cache regardless of key. Alternatively I need a way to find all the keys which are currently cached.

When we cache items we

2条回答
  •  不思量自难忘°
    2021-01-15 06:46

    Cache is faster than properties? Don't think so, check out this:

    function propertiesUser() { // 1272.0 , 1135.0
      var value = { a: 'a', b: 'b' }
      var key = 'ab';
      PropertiesService.getUserProperties().setProperty(key, value);
      var i = 0;
      var t = Date.now();
      while (i<100) {
        Logger.log( PropertiesService.getUserProperties().getProperty(key))
        i++
      }
      Logger.log( Date.now()-t);
    }
    
    function propertiesScript() { // 1190.0
      var value = { a: 'a', b: 'b' }
      var key = 'ab';
      PropertiesService.getScriptProperties().setProperty(key, value);
      var i = 0;
      var t = Date.now();
      while (i<100) {
        Logger.log( PropertiesService.getScriptProperties().getProperty(key))
        i++
      }
      Logger.log( Date.now()-t);
    }
    
    function cache() { // 4141.0
      var value = { a: 'a', b: 'b' }
      var key = 'ab';
      CacheService.getUserCache().put(key, JSON.stringify(value))
      var i = 0;
      var t = Date.now();
      while (i<100) {
        Logger.log( CacheService.getUserCache().get(key) )
        i++
      }
      Logger.log( Date.now()-t);
    }
    

提交回复
热议问题