'use strict';
/**
 * model
 */
export default class extends think.model.base {
  /**
   * options cache key
   * @type {String}
   */
  cache_key = 'website_options';
  /**
   * options cache time
   * @type {Number}
   */
  cache_time = 30 * 24 * 3600 * 1000;
  /**
   * get options
   * @return {} []
   */
  getOptions(){
    return think.cache(this.cache_key, async () => {
      let data = await this.select();
      let result = {};
      data.forEach(item => {
        result[item.key] = item.value;
      });
      return result;
    }, {
      type: 'memory',
      timeout: this.cache_time
    });
  }
  /**
   * update options
   * @return {} []
   */
  updateOptions(key, value){
    let data = think.isObject(key) ? think.extend({}, key) : {[key] : value};

  }
}
@@ -134,18 +134,17 @@
 %0A  cache
-_k
+K
 ey = 'we
@@ -174,26 +174,21 @@
   * 
+cache 
 options
- cache time
 %0A   
@@ -200,14 +200,14 @@
 pe %7B
-Number
+Object
 %7D%0A  
@@ -221,38 +221,105 @@
 ache
-_time = 30 * 24 * 3600 * 1000;
+Options = %7B%0A    timeout: 30 * 24 * 3600 * 1000,%0A    type: !think.isMaster ? 'file' : 'memory'%0A  %7D
 %0A  /
@@ -416,10 +416,9 @@
 ache
-_k
+K
 ey, 
@@ -602,68 +602,25 @@
  %7D, 
-%7B%0A      type: 'memory',%0A      timeout: this.cache_time%0A    %7D
+this.cacheOptions
 );%0A 
@@ -675,16 +675,22 @@
    */%0A  
+async 
 updateOp
@@ -786,14 +786,723 @@
 value%7D;%0A
+    let cacheData = await think.cache(this.cacheKey, undefined, this.cacheOptions);%0A    if(think.isEmpty(cacheData))%7B%0A      cacheData = await this.getOptions();%0A    %7D%0A    let changedData = %7B%7D;%0A    for(let key in data)%7B%0A      if(data%5Bkey%5D !== cacheData%5Bkey%5D)%7B%0A        changedData%5Bkey%5D = data%5Bkey%5D;%0A      %7D%0A    %7D%0A    //data is not changed%0A    if(think.isEmpty(changedData))%7B%0A      return;%0A    %7D%0A    let p1 = think.cache(this.cacheKey, think.extend(cacheData, changedData), this.cacheOptions);%0A    let promises = %5Bp1%5D;%0A    for(let key in changedData)%7B%0A      let value = changedData%5Bkey%5D;%0A      let p = this.where(%7Bkey: key%7D).update(%7Bvalue: value%7D);%0A      promises.push(p);%0A    %7D%0A    return Promise.all(promises);
 %0A  %7D%0A%7D

add options operate method