代码之家  ›  专栏  ›  技术社区  ›  Dan Monego

防止flex缓存外部资源

  •  0
  • Dan Monego  · 技术社区  · 17 年前

    我正在编写一个flex应用程序,它每隔几秒钟轮询服务器上的一个xml文件以检查更新的数据,但我在阻止它缓存数据和对更新的数据做出响应时遇到了问题。

    我尝试使用IIS控制面板设置标题以使用以下内容,但没有任何运气:

    CacheControl: no-cache
    Pragma: no-cache
    

    我还尝试在请求URL的末尾添加一个随机的HTTP GET参数,但这似乎是在发出请求之前由HttpService类剥离的。下面是实现它的代码:

    http.url = "test.xml?time=" + new Date().getMilliseconds();
    

    (mx.messaging.messages::HTTPRequestMessage)#0
      body = (Object)#1
      clientId = (null)
      contentType = "application/x-www-form-urlencoded"
      destination = "DefaultHTTP"
      headers = (Object)#2
      httpHeaders = (Object)#3
      messageId = "AAB04A17-8CB3-4175-7976-36C347B558BE"
      method = "GET"
      recordHeaders = false
      timestamp = 0
      timeToLive = 0
      url = "test.xml"
    

    有人处理过这个问题吗?

    2 回复  |  直到 17 年前
        1
  •  2
  •   Chris W. Rea    17 年前

        2
  •  0
  •   Dylan    16 年前

    我使用getTime()将日期转换为数字字符串,实现了这一点。我也换了一张去邮局的票。缓存不同的文件扩展名时出现了一些问题。例如,浏览器和应用程序可能不会缓存.php或.jsp之类的标准动态扩展

    private var myDate:Date = new Date();
    [Bindable]
    private var fileURLString:String = "http://www.mysite.com/data.txt?" + myDate.getTime();
    

    我还向它抛出了大量的标题参数,但它们从未完全做到这一点。示例:

    // HTTPService called service
    service.headers["Pragma"] = "no-cache";  // no caching of the file
    service.headers["Cache-Control"] = "no-cache";
    
    推荐文章