2016-12-06 105 views
0

我有開始這樣一個web應用程序:刪除瓶內存緩存

#It starts here 
@app.route('/game') 
def game(): 

裏面game,它動態地構建一個圖像與PIL並將其保存到/static/testing_image.png

那麼它呈現的模板。

return render_template('game.html', 
          file_name=file_name, 
          image_width=SQ_SIZE, 
          sleep_time=1000 
          ) 

現在,裏面game.html,什麼情況是,我等sleep_time毫秒,然後我想去再打電話game,從而使新圖像的生成和顯示

下面的代碼會等待圖像完全加載後顯示,等待和重定向。

function LoadImage() { 
    var img = new Image(), 
     x = document.getElementById("image"); 

    img.onload = function() { 
     x.src = img.src; 
     var sleep_time={{sleep_time}}; 
     setTimeout(function(){ 
      //I REDIRECT HERE 
      window.location="{{url_for('game')}}"; 
     }, sleep_time); 

    }; 

    img.src="{{url_for('static', filename=file_name) }}"; 
} 

的問題

問題當然是將圖像從內存緩存提供的,即使底層文件,/static/testing_image.png已經被更新,燒瓶沒有得到新的一。

enter image description here

您可以在下面看到testing_image.png從緩存中。

我的問題是雙重的。

  1. 我應該以不同的方式做到這一點?
  2. 如果不是,我該如何強制燒瓶在圖像上重新加載?

回答

1

有可能是一個更好的方法來構造這個,但很難說,沒有看看你的代碼的其餘部分。至於破壞緩存,你應該能夠使用:

http://flask.pocoo.org/snippets/40/

+0

嗯,這是本質上是調用自身的模板。我只是想在第一個調用之後進行調用,而不是在緩存上保存任何內容。 – elelias