Back

在webservice中不要返回 无内容的结果( don't return blank result in webservice )

发布时间: 2013-04-05 08:24:00

有两个系统,之间用 webservice(json  格式)通信,系统A 读取系统B。  ( there are 2 systems: A and B. A read the web service from B )

系统A有一层缓存系统,会对系统B返回的结果做缓存。但是有个条件:系统B给的结果必须是非空的。 ( system A has a cache system , but it can only cache non-blank values ) 

结果系统B的一个特点是,找不到结果时,会返回 无内容的json 字符,如: [] ,  {}   ( but the system B always return blank values ) 

结果系统A就无法缓存。造成了系统B很大的负担。    ( so System A has to read blank values again and again from System B )

解决方案:  系统B在找不到对应结果时,要返回一个默认的json, 例如: (the solution is to provide default values when result not found. e.g. )

{ 
  results: [
    'I am the default value! '
  ]
}

道理很简单,效果很明显!  CPU的占用率 马上从 50% 降低到5 % 以下 ( this is very simple but very important to the system B, the CPU cost reduced from 50% to 5% ) 

Back