4

最終変更、有効期限、キャッシュ制御ヘッダーを送信しているアプリエンジンアプリケーションのブラウザで画像をキャッシュすることに少し問題がありますが、画像は毎回サーバーから読み込まれます。コードのヘッダー部分は次のとおりです。

response ['Content-Type'] ='image / jpg'

response ['Last-Modified'] = current_time.strftime('%a、%d%b%Y%H:%M:%S GMT')

response ['Expires'] = current_time + timedelta(days = 30)

response ['Cache-Control'] ='public、max-age = 2592000'

4

1 に答える 1

7

これがdpasteの修正コピーのサンプルコードです

def view_image(request, key):
  data = memcache.get(key)  
  if data is not None:  
    if(request.META.get('HTTP_IF_MODIFIED_SINCE') >= data['Last-Modified']):  
      data.status_code = 304  
    return data  
  else:  
    image_content_blob = #some code to get the image from the data store  
    current_time = datetime.utcnow()
    response = HttpResponse()
    last_modified = current_time - timedelta(days=1)
    response['Content-Type'] = 'image/jpg'
    response['Last-Modified'] = last_modified.strftime('%a, %d %b %Y %H:%M:%S GMT')
    response['Expires'] = current_time + timedelta(days=30)
    response['Cache-Control']  = 'public, max-age=315360000'
    response['Date']           = current_time
    response.content = image_content_blob

    memcache.add(image_key, response, 86400)
    return response
于 2010-02-04T15:04:57.797 に答える