Browser image caching - app-engine-patch application

I have a small problem with caching images in the browser for my application with the application. I send the latest changes, the cache headers expire, but the image is downloaded from the server every time. Here is the header part of the code:

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
source share
1 answer

Here is a sample code for my copy of fix in dpaste here

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 
+7
source

Source: https://habr.com/ru/post/1300075/


All Articles