I have an ImageController class that is called to retrieve an image from the database. The result is stored in the cache through use of the attribute [OutputCache].
Here is the controller:
[OutputCache(Duration=3600,VaryByParam="name")]
public ActionResult Show(string name)
{
var imageByte = retrieveByteFromDatabase(name);
if(imageByte != null && imageByte.Length > 0)
{
return File(imageByte, "image/png");
}
}
Then inside the view, it is being accessed like this:
<img class="image" src="@Url.Action( "show", "image", new { name = "Image.png" })" />
Now, this is an image that is uploaded to the database by a user, and will need to be removed from the cache when another image is uploaded. It is uploaded with this:
[HttpPost]
public ActionResult UploadImage(HttpPostedFileBase file)
{
uploadToDatabase(file);
return RedirectToAction("Index", "Home");
}
with the view...
@using (Html.BeginForm("UploadImage", "Image", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="logo" />
<button class="button" type="submit">Upload</button>
}
Is it possible to remove just this one image from the cache upon uploading a new one? If so - how?
Thanks!