Hey all I have been working to get my 20+ thumbnails into a cache state so it doesn't always going the server to get the images each time the page is loaded/reloaded.
I have implemented the "eTag" into my response call like so:
var uriFetcher = new UriFetcher(fileUri);
var tempPath = uriFetcher.FetchFile();
var mime = MimeType(tempPath);
//displays like: xxxxxx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.png
//This is the image file name. These names do not change.
string theETag = tempPath.Split('\\').Last();
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.Cache.SetLastModified(DateTime.Now);
context.Response.Cache.SetValidUntilExpires(true);
context.Response.Cache.SetExpires(DateTime.Now.AddYears(1));
context.Response.Cache.SetMaxAge(new TimeSpan(1, 0, 0));
context.Response.CacheControl = "private";
context.Response.ContentType = mime;
//Add current image file name to the eTag
context.Response.AddHeader("ETag", "\"" + theETag + "\"");
var disposition = new ContentDisposition
{
FileName = Path.GetFileName(tempPath),
Inline = mime.Contains("image")
};
context.Response.AddHeader("content-disposition", disposition.ToString());
try {
context.Response.TransmitFile(tempPath);
} catch {
context.Response.TransmitFile(errorUri);
}
Now after the .cs part above it goes to a JavaScript function that's using the jQuery framework in order to place it onto the page for the user to see:
var imgThumbnail = img('thumbnail', '/' + thumbnailId + '/Thumbnail', preload)
.tipsy({
html: true,
assetMode: false,
fallback: assetData.Tooltip.html(),
gravity: ($container.closest('#Side').length == 0) ? $.fn.tipsy.auto : 'e',
topOffset: topOffset
});
if (assetData.ProcessingRollupStatus != null) {
if (assetData.ProcessingRollupStatus === 'Processing') {
imgThumbnail.addClass('processing-status-processing');
} else if (assetData.ProcessingRollupStatus === 'Waiting') {
imgThumbnail.addClass('processing-status-waiting');
}
}
$container
.addClass('asset-item')
.data('AssetData', assetData)
.attr('id', assetData.Id)
.append(imgThumbnail);
And from Firefox this is what the output looks like:
So the part where I am having issues is when I go check for the eTag when the page is loaded/refreshed. I'm not really sure what (or where) I should put that code in order for it to not load the images if they are already in cache?
I was thinking something like this:
var requestedETag = context.Request.Headers["If-None-Match"];
if (requestedETag == last)
{
return new HttpStatusCodeResult(HttpStatusCode.NotModified);
//context.Result = new StatusCodeResult(304);
} else {
...........
So, anyone care to enlighten me as to how to go about doing this check?